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

1

7

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?

Harshman answered 1/4, 2018 at 3:46 Comment(2)
apollo-upload-client is a client alternativeAllison
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 clearHarshman
K
13

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

Katti answered 7/6, 2019 at 17:37 Comment(6)
How about byte array? I am trying to pass in a byte array to a mutation. #57447427Boracic
Do you just have the array that you need to pass in? Or is it a blob or something?Katti
It is a blob I want to pass in.Boracic
@SimplyComplexable: (newbie here)I dont get it, can u please provide images?Backsword
@Backsword I just edited the example with an image. The image is a little different but should illustrate what what you're trying to do.Katti
@Katti an image different than the example is more confusingBornstein

© 2022 - 2024 — McMap. All rights reserved.