Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send a file with a Graphql Mutation in insomnia.rest?

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?

like image 377
sgaseretto Avatar asked Apr 01 '18 03:04

sgaseretto


People also ask

How do I send files with insomnia?

To upload a video using Insomnia, you have to set the body as multipart and add the file and all the other necessary parameters. The upload[file] parameter needs to be changed to type 'File' using the small arrow at the right side of the row. The Multipart body should look similar to the sample image.


1 Answers

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

like image 187
SimplyComplexable Avatar answered Sep 28 '22 08:09

SimplyComplexable