Title: Streaming file upload is not working · Issue #433 · graphql-python/gql · GitHub
Open Graph Title: Streaming file upload is not working · Issue #433 · graphql-python/gql
X Title: Streaming file upload is not working · Issue #433 · graphql-python/gql
Description: from gql import gql, Client from gql.transport.aiohttp import AIOHTTPTransport import aiofiles gql_query = gql(''' mutation create($input: ProductDocumentCreateMutationInput) { createProductDocument(input: $input) { productDocument{ id }...
Open Graph Description: from gql import gql, Client from gql.transport.aiohttp import AIOHTTPTransport import aiofiles gql_query = gql(''' mutation create($input: ProductDocumentCreateMutationInput) { createProductDocumen...
X Description: from gql import gql, Client from gql.transport.aiohttp import AIOHTTPTransport import aiofiles gql_query = gql(''' mutation create($input: ProductDocumentCreateMutationInput) { createPr...
Opengraph URL: https://github.com/graphql-python/gql/issues/433
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Streaming file upload is not working","articleBody":"```\r\nfrom gql import gql, Client\r\nfrom gql.transport.aiohttp import AIOHTTPTransport\r\nimport aiofiles\r\n\r\n\r\ngql_query = gql('''\r\n mutation create($input: ProductDocumentCreateMutationInput) {\r\n createProductDocument(input: $input) {\r\n productDocument{\r\n id \r\n }\r\n }\r\n }\r\n\r\nquery getProductDoc($id: ID!) {\r\n productDocument(id: $id) {\r\n id\r\n file_category\r\n file\r\n }\r\n }\r\n''')\r\n\r\nasync def stream_file(filepath):\r\n async with aiofiles.open(filepath, \"rb\") as f:\r\n while True:\r\n chunk = await f.read(64 * 1024)\r\n if not chunk:\r\n break\r\n yield chunk\r\n\r\ntransport = AIOHTTPTransport(\r\n url='url',\r\n headers={\"Authorization\": f\"Bearer {auth_token}\"},\r\n )\r\nasync with Client(transport=transport, fetch_schema_from_transport=True) as gql_session\r\n filepath = 'path/to/product_doc.pdf'\r\n data = {\r\n \"user\": 'user_id',\r\n \"file_category\": 'product_doc'\r\n \"file\": stream_file(filepath),\r\n }\r\n \r\n result = await gql_session.execute(\r\n gql_query,\r\n operation_name=\"create\",\r\n variable_values={\"input\": data},\r\n upload_files=True,\r\n )\r\n```\r\nIn above I am trying to stream file upload as shown in the `gql` documentation. But I get following error\r\n\r\n```\r\n[ERROR] Exception: Failed to upload {'message': 'Must provide query string.'}\r\nTraceback (most recent call last):\r\nFile \"file_upload.py\", line 143, in main\r\nresult = await gql_session.execute(\r\nFile \"/usr/local/lib/python3.10/site-packages/gql/client.py\", line 1231, in execute\r\nraise TransportQueryError(\r\ngql.transport.exceptions.TransportQueryError: {'message': 'Must provide query string.'}\r\n\r\nDuring handling of the above exception, another exception occurred:\r\nTraceback (most recent call last):\r\nFile \"/usr/local/lib/python3.10/asyncio/runners.py\", line 44, in run\r\n return loop.run_until_complete(main)\r\nFile \"/usr/local/lib/python3.10/asyncio/base_events.py\", line 649, in run_until_complete\r\n return future.result()\r\n File \"file_upload.py\", line 148, in main\r\n raise Exception(f\"Failed to upload {exp}\")\r\nException: Failed to upload {'message': 'Must provide query string.'}\r\n```\r\n\r\n**System info:**\r\n - OS: Ubuntu 22.04\r\n - Python version: 3.10\r\n - gql version: 3.4\r\n - graphql-core version: 3.2.3\r\n","author":{"url":"https://github.com/myscfwork","@type":"Person","name":"myscfwork"},"datePublished":"2023-09-07T21:13:10Z","url":"https://github.com/graphql-python/gql/issues/433"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:43359fc5-85e6-1e3e-2c4e-0e6d2c73baaf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9856:2B9B04:1B20F5F:22F5ADB:6AFFC3BD |
| html-safe-nonce | 625351ab1ce572cdef10553975cb8be643dfc0363f13925aa1eb77499a05609c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODU2OjJCOUIwNDoxQjIwRjVGOjIyRjVBREI6NkFGRkMzQkQiLCJ2aXNpdG9yX2lkIjoiNzM1ODg1MzA4OTY1MjA5Nzk4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cde89e079c16b1769142ec59601262b1e48173be67ea19b59de56d33af00d524 |
| hovercard-subject-tag | issue:1886570689 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/graphql-python/gql/433/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e4b7ce1e0dd0f9d10ae74d12b8d600eb16502dd429f46941f1e37fc86ab4a4fd/graphql-python/gql/issues/433 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e4b7ce1e0dd0f9d10ae74d12b8d600eb16502dd429f46941f1e37fc86ab4a4fd/graphql-python/gql/issues/433 |
| og:image:alt | from gql import gql, Client from gql.transport.aiohttp import AIOHTTPTransport import aiofiles gql_query = gql(''' mutation create($input: ProductDocumentCreateMutationInput) { createProductDocumen... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | myscfwork |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1e805b832df235bb21305db712c3b6432920019dfc12cb25b9cb8d3b0c9403cf |
| turbo-cache-control | no-preview |
| go-import | github.com/graphql-python/gql git https://github.com/graphql-python/gql.git |
| octolytics-dimension-user_id | 15002022 |
| octolytics-dimension-user_login | graphql-python |
| octolytics-dimension-repository_id | 62077169 |
| octolytics-dimension-repository_nwo | graphql-python/gql |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 62077169 |
| octolytics-dimension-repository_network_root_nwo | graphql-python/gql |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8fa4a54e6871c7908eda1c246ad5972982c0b59d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width