Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphql: Must provide query string

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)

like image 637
Avraam Mavridis Avatar asked Oct 19 '25 10:10

Avraam Mavridis


1 Answers

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.

like image 105
Daniel Rearden Avatar answered Oct 21 '25 22:10

Daniel Rearden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!