【发布时间】:2018-01-13 19:09:45
【问题描述】:
我有一个简单的 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`);
});
我的请求看起来像:
有什么帮助吗?
(请不要将其关闭为重复,因为其他帖子没有提供有关用户如何解决它的足够信息)
【问题讨论】:
-
尝试用
schema: schema,替换schema, -
@ChrisG 如果它不理解语法,它会抛出语法错误。
-
@ChrisG 在 ES6 中
{ schema }等价于{ schema: schema }。这是语法糖!不过眼光不错:这看起来像个错误。
标签: javascript node.js express graphql relay