Uploading a File with Upload Scalar and Insomnia
Uploading a File with “Upload” Scalar isn’t a big problem if you are using library like graphql-upload. But if you like just to try/simulate it with Insomnia, you need to know what happens under to hood.
In fact, you will send a multipart form request to the GraphQL server.
It is split in three parts (be careful, naming is important):
- operations, which contains the GraphQL query and variables
1 | { |
- map, which maps the file you would like to upload 0, with the GraphQL variable name file
- You can extend it, if you like to upload multiple files
1 | {"0":["variables.file"]} |
- 0, refers to the file, which you selected and would like to upload
Note: operations and map has the type “Text (Multi-line)” and not “File”.