2
votes

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}"}

enter image description here

1
pass variables in the operations arg - stackoverflow.com/a/62683397/6124657xadm

1 Answers

1
votes

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" } }

enter image description here