1

I am using graphql-request for graphQL queries at my frontend part (react). Server side using express-graphql. I have some ideas to handle that on backend side (your suggestions will be appreciated too), but searching how to handle frontend part.

Is it possible to send a FormData (image in my case) inside graphql-request query? Any examples?

Jack Hudzenko
  • 157
  • 3
  • 14

1 Answers1

1

Per their documentation, this is the format:

const client = new GraphQLClient(endpoint, { headers: {} })
client.request(query, variables).then(data => console.log(data))

GraphQL doesn't easily handle image uploads, it probably would be easier to upload them elsewhere and send the image URL to your graphql server.

You could do something like this:

yourClient.request(query, { id:1, imgURL:'http://foobar.com' })
.then(data => doSomethingWithData(data))
mhough
  • 86
  • 2
  • Thinking about such a solution too. Too much problems with image uploading directly through graphQL. Thanks for the answer! – Jack Hudzenko Apr 18 '18 at 13:10