5

Just updated to 'graphql-server-express' version 1.3.0 and now I am getting this error when running any mutations:

POST body missing. Did you forget use body-parser middleware?

When initializing the server, I am including the "body-parser" package so I am not sure what is going on here. Any ideas?

Server Config:

    //GraphQL Server
    graphQLServer.use(

        //GRAPHQL Endpoint
        `/${settings.public.graphql.endpoint}`,

        //Parse JSON
        bodyParser.json(),

        //authenticate
        authenticateRequest,

        //GRAPHQL Server
        graphqlExpress(req => {

            return {
                schema: schema,
                context: req
            }
        })

    );

Example Request:

curl 'http://localhost:5050/graphql' \
  -H 'authorization: Bearer xxxxxxxxxxx.xxxxxxxxxxx' \
  -d '{
    "query": "mutation { sensorData(sensorValue: \u0027asdasdasdasd \u0027)}",
    "variables": {}
    }
  }'
matt
  • 63
  • 1
  • 4

1 Answers1

8

Set Content-Type: application/json header in the request (docs)

curl 'http://localhost:5050/graphql' \
  -H "Content-Type: application/json" \
  -H 'authorization: Bearer xxxxxxxxxxx.xxxxxxxxxxx' \
  -d '{
    "query": "mutation { sensorData(sensorValue: \u0027asdasdasdasd \u0027)}",
    "variables": {}
    }
  }'
Bless
  • 5,052
  • 2
  • 40
  • 44