jaydenseric / graphql-upload

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 131 forks source link

Using multiple arguments causes "Variable XXX got invalid value { resolve: [function], reject: [function], promise: {} }" #308

Closed pedropapa closed 2 years ago

pedropapa commented 2 years ago

I'm using graphql-upload with NestJS, everything works fine if I have just one graphql argument in the file upload mutation. In my case I also need to send a type argument as a String to know in the server-side how I should handle this upload.

When I add this new argument in the mutation and send it in to the request I start having this error Variable \"$type\" got invalid value { resolve: [function], reject: [function], promise: {} }. I wasn't able to dig into graphql-upload source code to find out what's happening under the hood.

Screen Shot 2022-05-23 at 9 41 25 PM

If I remove type argument from the mutation and from Postman request I get the file uploaded without errors.

Repro: https://github.com/pedropapa/github-upload-issue-repro

jaydenseric commented 2 years ago

The problem is, the map field of the GraphQL multipart request is supposed to only map what parts of the operation JSON contain the file upload scalar values, but you are also incorrectly using it to map a string value user. The numbered fields after map are only meant to contain the files, but in your case the field named 1 incorrectly contains a string user and is not a file field.

You can include the non file upload GraphQL variables in the operations field JSON. This might make more sense if you re-read the spec very carefully about what is in each of the multipart request fields:

https://github.com/jaydenseric/graphql-multipart-request-spec#multipart-form-field-structure