You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a very specific use case where my express.js app receives a file and then forwards it to a GraphQL API. Based on the example from the quickstart, I came up with code like this:
The problem is that when I try to run the upload (by sending a request with a file to /endpoint), graphql-request sends a JSON payload of multer's representation of the file, instead of the file itself, and my GraphQL server (Python, strawberry-based) refuses to parse that. I also tried to pass a buffer (file.buffer) instead of a file, but no luck either. Note that replacing the following part:
request("http://localhost:8000/graphql",mutation,{file: createReadStream('./file'),// from fs})
works just fine.
I believe the underlying issue is that the FormData object, constructed before sending the request, doesn't understand multer's representation of a file. I managed to get around that by constructing my own FormData object and sending it without using graphql-request.
// graphql-multipart-request-spec relatedletoperations={"query": mutation,"variables": {"file": null}}letrequestMap={"file": ["variables.file"]}letformData=newFormData()formData.append("operations",JSON.stringify(operations))formData.append("map",JSON.stringify(requestMap))formData.append("file",file.buffer,{filename: "file",contentType: "audio/wav"})// setting the filename and contentType seems to be enough - it's audio/wav in my case
Is this the expected behavior? Or is there any other way to pass a buffer/file to request so that graphql-reqest understand that it's actually a file?
Thanks!
The text was updated successfully, but these errors were encountered:
Hi,
first of all thanks for such a great project!
I have a very specific use case where my express.js app receives a file and then forwards it to a GraphQL API. Based on the example from the quickstart, I came up with code like this:
The problem is that when I try to run the upload (by sending a request with a file to
/endpoint
),graphql-request
sends a JSON payload of multer's representation of the file, instead of the file itself, and my GraphQL server (Python, strawberry-based) refuses to parse that. I also tried to pass a buffer (file.buffer
) instead of a file, but no luck either. Note that replacing the following part:with
works just fine.
I believe the underlying issue is that the
FormData
object, constructed before sending the request, doesn't understand multer's representation of a file. I managed to get around that by constructing my ownFormData
object and sending it without usinggraphql-request
.Is this the expected behavior? Or is there any other way to pass a buffer/file to
request
so thatgraphql-reqest
understand that it's actually a file?Thanks!
The text was updated successfully, but these errors were encountered: