4

I have a simple express graphql server:

const schema = require('./schema');
const express = require('express');
const graphqlHTTP = require('express-graphql');
const cors = require('cors')
const bodyParser = require('body-parser');


const app = express();
app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.use('/graphql', graphqlHTTP(req => {
  return ({
  schema,
  pretty: true,
  })
}));

const server = app.listen(9000, err => {
  if (err) { return err; }
  console.log(`GraphQL server running on http://localhost:${9000}/graphql`);
});

And my request looks like:

enter image description here

Any help?

(Please don't close it as duplicate because the other post does not provide enough info on how the user solved it)

Avraam Mavridis
  • 8,698
  • 19
  • 79
  • 133

1 Answers1

4

You need to specify application/json in your Content-Type header -- you currently have text/plain. You've included the body parser middleware on the server, but it relies on that header in your request to know when it needs to actually parse the response into JSON.

Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183