Closed vincentwinkel closed 2 years ago
Hi @vincentwinkel, if you paste the operations JSON in a markdown code block I can copy from I'll write the structure of a correct request for you; the problem is that the GraphQL multipart request form fields you are attempting is not according with the spec:
https://github.com/jaydenseric/graphql-multipart-request-spec#multipart-form-field-structure
My bad @jaydenseric I didnt expect an anwer so fast. I wanted to add the version used but then I realised it's out of date (v13), so I'm trying to install the last version, but get another issue aas mentionned here
Closing because this is not an issue with graphql-upload
but a usage question about how to structure a GraphQL multipart request.
The numbered fields following operations
and map
should only be file fields, but you are incorrectly adding one for a string value. You are also missing the variables
JSON within the operations
field. The variables
should contain the same stuff as a regular GraphQL post request, just with file values replaced with null
.
Like said above, I tried to add the variables
directly in the operations
field, it also didnt work, because I kept the wrong mapping.
Now, it indeed works. I post for the ones who are stuck as well.
Operations: { "query": "mutation a($file: Upload!, $input: String!) { uploadFile(file: $file, input: $input) }", "variables": { "file": true, "input": "toto" } }
Map: { "0": ["variables.file"] }
Thanks
After days of investigation (supertest, apollo, graphql-upload, ...) I finally could find the origin of my issue: when I upload a file, using extra payload directly in the query, it works:
If I add the extra payload in variables, it does'nt work (I replaced here
input
from an object to a string for simplicity of debugging):Operations:
{ "query": "mutation a($file: Upload!, $input: String!) { uploadFile(file: $file, input: $input) }" }
Map:{ "0": ["variables.file"], "1": ["variables.input"] }
I found a lot of examples / tuto / forum topics explaininig how to deal with supertest, like this one, very helpful, but then I realiseed nobody was trying to add more than 1 param (the file to upload). Is there really a bug or I misunderstand something? I also tried to use FormData (not compatible anymore with supertest), to inject the variables directly in
operations
, to try with postman, curl, supertest, nodejs, ...