【发布时间】:2018-04-01 15:11:46
【问题描述】:
更新:apollo 已更新代码和文档,因此问题现在无关紧要
预期结果
使用来自https://github.com/apollographql/apollo-tutorial-kit 的以下 sn-p 启动 apollo-server-express。
import express from 'express';
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
import bodyParser from 'body-parser';
import schema from './data/schema';
const GRAPHQL_PORT = 3000;
const graphQLServer = express();
graphQLServer.use('/graphql', bodyParser.json(), graphqlExpress({ schema }));
graphQLServer.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
graphQLServer.listen(GRAPHQL_PORT, () => console.log(`GraphiQL is now running on http://localhost:${GRAPHQL_PORT}/graphiql`));
实际结果:
在 apollo-server-express 的任何实现中,使用文档、使用 https://github.com/apollographql/apollo-tutorial-kit 等。我一遍又一遍地收到以下堆栈跟踪:
Error: Must provide document
at invariant (~/node_modules/graphql/jsutils/invariant.js:18:11)
at Object.validate (~/node_modules/graphql/validation/validate.js:58:34)
at doRunQuery (~/node_modules/apollo-server-core/dist/runQuery.js:80:38)
at ~/node_modules/apollo-server-core/dist/runQuery.js:20:54
at <anonymous>
如何重现问题:
git clone https://github.com/apollographql/apollo-tutorial-kit.git
cd apollo-tutorial-kit
yarn/npm i
npm start
【问题讨论】:
-
4 个月前,我认为阿波罗已经很老了,一直在变化
-
入门套件工作正常。这听起来像是您在响应您提出的请求时遇到的错误。通常,当请求正文格式错误或缺少
Content-Type: application/json标头时会引发该错误。您应该更新您的问题,以包括您如何尝试向服务器发出请求。 -
清除我的 npm 缓存 && node_modules 后,我让它工作了!谢谢大家
标签: javascript graphql apollo graphql-js apollo-server