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:
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.