javascript - Graphql: Must provide query string - Stack Overflow

I have a simple express graphql server:const schema = require('.schema');const express = re

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:

Any help?

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

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:

Any help?

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

Share Improve this question asked Aug 6, 2017 at 9:34 Avraam MavridisAvraam Mavridis 8,94022 gold badges87 silver badges135 bronze badges 3
  • Try replacing schema, with schema: schema, – user5734311 Commented Aug 6, 2017 at 9:37
  • @ChrisG it would have throw Syntax error, if it didnt understand the syntax. – Avraam Mavridis Commented Aug 6, 2017 at 9:40
  • @ChrisG In ES6 { schema } is equivalent to { schema: schema }. It's syntactic sugar! Good eye, though: this looks like a bug. – Ziggy Commented Oct 10, 2017 at 3:51
Add a ment  | 

1 Answer 1

Reset to default 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745354687a4624045.html

相关推荐

  • javascript - Graphql: Must provide query string - Stack Overflow

    I have a simple express graphql server:const schema = require('.schema');const express = re

    20小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信