Skip to content Skip to sidebar Skip to footer

Graphql Mutation To Upload File With Other Fields

I'm using Ariadne to create a python GraphQL server and a I have the following mutation to upload a file: type Mutation { uploadUserAvatar(file: Upload!): Boolean! } And the f

Solution 1:

Only files needs 'special treatment', other data pass in classic way, by "variables".

curl http://localhost:8080/ \
  -F operations='{ "query":"mutation ($userid: String!, $file: Upload!) { uploadUserAvatar(userid: $userid, file: $file) }", "variables": { "file": null, "userid": "abc1234" } }' \
  -F map='{ "0": ["variables.file"] }' \
  -F 0=@image.jpeg

Solution 2:

Don't wrap the content part of the form data like -F name=content, like you are doing with the userid. Try this:

curl http://localhost:8080/ \
  -F operations='{ "query":"mutation ($userid: String!, $file: Upload!) { uploadUserAvatar(userid: $userid, file: $file) }","variables": { "file": null, "userid": null } }' \
  -F map='{ "0": ["variables.file"], "1": ["variables.userid"] }' \
  -F 0=@etiqueta_LG.jpeg \
  -F 1=abc1234

I have not tried this but I read the curl docs (man curl) and read the section on form data -F.


Post a Comment for "Graphql Mutation To Upload File With Other Fields"