- Open Postman and create a new request.
- Set the request method to “POST” and the URL to your GraphQL API endpoint.
- Click on the “Body” tab and select the “form-data” option.
- Add a new key-value pair with the key as “operations” and the value as a JSON string containing the GraphQL query and the variables you want to send.For example
{ "query": "mutation ($file: Upload!, $fileName: String!) { uploadFile(file: $file, fileName: $fileName) { id } }", "variables": { "file": null, "fileName": "file-name-here.ext" } }
Note that the “file” variable is of type
Upload!
and the “fileName” is a regular variable. - Add another key-value pair with the key as “map” and the value as a JSON string containing the mapping of the “file” variable to the actual file you want to upload.For example:
{ "0": ["variables.file"] }
Note that the “0” key represents the index of the file you want to upload, and the value is an array containing the path to the “file” variable.
- Click on the “Choose Files” button next to the “map” field and select the file you want to upload.
- Click on the “Send” button to send the request.
Your GraphQL API should now receive the GraphQL query along with the additional variable and the file upload.