I am trying to use Postman to upload a file to GraphQL.
I know how I can upload a file, however, in my mutation I have to pass a String!
together with the Upload!
.
I am not sure where I can pass this String!
in Postman.
My mutation:
mutation AddBookImageOne($bookId: string, $bookImageOne: Upload!){
addBookImageOne(bookId: $bookId, bookImageOne: $bookImageOne)
}
I tried to pass bookId
in the variables
key but I keep getting the error:
"message": "Variable "$bookId" of required type "String!" was not provided.",
I checked this: Graphql mutation to upload file with other fields but they use CURL
"Operations" in postman field is:
{"query":"mutation AddBookImageOne($bookId: String!, $bookImageOne: Upload!){\n addBookImageOne(bookId: $bookId, bookImageOne: $bookImageOne)\n}"}
You can use Form-Data to do this. Perfect, that works!
Sending GraphQL queries in the request bodyOpen a new request tab in Postman and enter your GraphQL endpoint URL in the address field. Select POST from the request method dropdown list. Under the Body tab, select the GraphQL body type. Enter your GraphQL query in the Query editor.
GraphQL Yoga supports GraphQL Multipart Request Specification which allows you to upload files via HTTP and consume the binary data inside GraphQL Resolvers. In GraphQL Yoga, you consume uploaded files or blobs as WHATWG standard File or Blob objects you might be familiar from the browser's API.
For uploading files via GraphQL you will need: graphql-multipart-request-spec - will be good if you get acquainted with this spec. apollo-upload-server - for parsing multipart/form-data POST requests via busboy and providing File s data to resolve function as argument.
SOLVED thanks to @xadm
I had to pass the variables in the operations
field like:
{"query":"mutation AddBookImageOne($bookId: String!, $bookImageOne: Upload!){\n addBookImageOne(bookId: $bookId, bookImageOne: $bookImageOne)\n}", "variables": { "bookImageOne": null, "bookId": "be96934c-d20c-4fad-b4bb-a1165468bad9" } }`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With