Reputation: 8920
I am using the fetch
api to make a POST
request sending a GraphQL
fetch( dbUrl, {
method : 'post',
body : JSON.stringify( {
graphql : "mutation M {saveUser(name:'Avraam')}"
} )
} )
On the request body I can see clearly:
On the server I am using restify
and I have:
server.use( restify.bodyParser() );
and
import { GraphQLAnimationSchema } from '../schemas/GraphQLAnimationSchema';
const requestBuilder = query => graphql( GraphQLAnimationSchema, query )
...
...
export default {
'/data' : {
post : ( req, res ) => requestHandler( requestBuilder( req.body.graphql ), res )
};
The GraphQL response with
{"errors":[{"message":"Syntax Error GraphQL request (1:1) Unexpected EOF\n\n1: \n ^\n"}]}
Should I use a specific kind of Headers
, (I have tried to use various Headers) but it doesnt seem to solve the problem.
Upvotes: 0
Views: 3022
Reputation: 8920
Solved by using FormData
const data = new FormData()
data.append( 'graphql', "mutation M {saveUser(name:'Avraam')}" )
fetch( dbUrl, {
method : 'post',
body : data
} )
Upvotes: 3