hasura / graphqurl

curl for GraphQL with autocomplete, subscriptions and GraphiQL. Also a dead-simple universal javascript GraphQL client.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Isn't it need to Content-Type headers?

stardustrain opened this issue · comments

First, I appreciate made a good library for GraphQL environment.

I have a question in use graphqurl.

Isn't it need to "Content-Type": "application/json" headers when requests to GraphQL server?

I'd made a simple GraphQL server with fastify + mercurius, and using graphqurl in CLI but an error occurred this:
image

I was found that 'content-type': 'text/plain;charset=UTF-8' in request headers, therefore I think parsing body with inappropriate parsing logic when receiving request in fastify server.

I'm confused as to whether I need to modify the server's parsing logic for instance like this?

fastify.addContentTypeParser('text/plain', { parseAs: 'string' }, function (req, body, done) {
  try {
    const json = JSON.parse(body)
    done(null, json)
  } catch (err) {
    err.statusCode = 400
    done(err, undefined)
  }
})

If this library is a problem and fixing it isn't a high priority, I'd like to try it.

@stardustrain yes adding a content-type header would be useful as some graphql servers expect it. Feel free to open a pull request with the suggested change.

@wawhal #98 I was created pull request related to this issue. Thank you for your kindness.