Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload does not work with gateway 1.0.5 #7701

Closed
MaximeDetne opened this issue Sep 19, 2024 · 5 comments
Closed

File upload does not work with gateway 1.0.5 #7701

MaximeDetne opened this issue Sep 19, 2024 · 5 comments

Comments

@MaximeDetne
Copy link

MaximeDetne commented Sep 19, 2024

I use GraphQL Mesh and hive-gateway (v1.0.5) to federate graphql apis based on strawberry+django.

I have a mutation with type Upload!, I'm able to upload a file directly on the strawberry API but not through hive-gateway.

On hive gateway I have (long after the sub api responded) : ERROR RangeError: Invalid string length

And on the sub API : code 400, message Bad request syntax (when sending thought hive-gateway)

I'm sending the exact same request with Altair Graphql client, it works when querying directly the sub api.

Environment:

  • OS: Docker node:22.9-alpine
  • "@graphql-hive/gateway": "^1.0.5",
    "@graphql-mesh/compose-cli": "^1.0.2",
    "@graphql-mesh/cross-helpers": "^0.4.6",
    "graphql": "^16.9.0"
  • NodeJS: 22.9
@MaximeDetne
Copy link
Author

I noticed graphql-mesh / yoga uses the File scalar to handle uploads as Strawberry uses "Upload". Could it be the issue here ?

@MaximeDetne
Copy link
Author

I created a repro here : https://github.com/MaximeDetne/mesh-strawberry

@enisdenjo
Copy link
Collaborator

Thanks for reporting @MaximeDetne! I've done some debugging and have discovered that your python server does not support chunked transfers (which is what is sent by Node because the FormData length is not known).

You can reproduce the issue by appending Transfer-Encoding: chunked to the upload request.

Here's a curl snippet:

curl localhost:8000 \
  -H 'Transfer-Encoding: chunked' \
  -F operations='{ "query": "mutation ($file: Upload!) { uploadFile(file: $file) { id } }", "variables": { "file": null } }' \
  -F map='{ "0": ["variables.file"] }' \
  -F [email protected]

@MaximeDetne
Copy link
Author

MaximeDetne commented Oct 1, 2024

Thank you @enisdenjo ! Do you know if there is a workaround on the graphql-mesh side ?

Can I force node not to use chunked transfers or can I provide the FormData length ?

@enisdenjo
Copy link
Collaborator

Sadly I cant think of a workouround that's simple enough. The thing with native FormData (which we use) is that it cannot accurately calculate the size when sending the data over the wire - so we cannot "just" calculate it and add a content-length header. For an accurate size - we'd need an extra dependency, like form-data, and we want to avoid extra dependencies as much as possible...

I am not familiar with Python, but I am quite sure this can be fixed there instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants