6
votes

I'm trying to upload an image with a graphql mutation to my server, how can I test this with insomnia.rest? the the Structured request for a Graphql Query doesn't show any field to add a file. Also, if this isn't posible with insomnia, what other alternative can I use to test something like this?

1
apollo-upload-client is a client alternativeMark Chackerian
where can I find examples of how to implement a client, I'm very new to react so I don't find their readme very clearsgaseretto

1 Answers

13
votes

You'll want to use the "Multipart" request type. Then add the following values:

  • operations: The graphql mutation in the format that is sent in the request, which should look something like below. (You can get this by using the GraphQL request option and switching to multipart form and then moving the values around).
{
 "query":"mutation UploadFile($file: File!) {\n  addResearch(file: $file)\n}",
 "variables":{ "file": null},
 "operationName":"UploadFile"
}
  • map: { "File": ["variables.file"] }
  • File: The file to upload. Click the dropdown on right beside the value input and choose "File" so that you can select a file.

Example image