Graphql:必须提供查询字符串
Graphql: Must provide query string
我有一个简单的 express graphql 服务器:
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`);
});
我的请求是这样的:
有什么帮助吗?
(请不要将其作为重复项关闭,因为另一个 post 没有提供足够的信息说明用户如何解决它)
您需要在 Content-Type header 中指定 application/json
-- 您目前有 text/plain
。您已经在服务器上包含 body 解析器中间件,但它依赖于您请求中的 header 来了解何时需要将响应实际解析为 JSON.
我有一个简单的 express graphql 服务器:
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`);
});
我的请求是这样的:
有什么帮助吗?
(请不要将其作为重复项关闭,因为另一个 post 没有提供足够的信息说明用户如何解决它)
您需要在 Content-Type header 中指定 application/json
-- 您目前有 text/plain
。您已经在服务器上包含 body 解析器中间件,但它依赖于您请求中的 header 来了解何时需要将响应实际解析为 JSON.