【发布时间】:2019-06-13 09:05:24
【问题描述】:
我正在按照这里的教程进行操作:Implementing GraphQL Using Apollo On an Express Server,我在浏览器http://localhost:7700/graphql 中收到错误GET query missing。
首先,我自己输入了所有代码。当我遇到错误时,我从GitHub: kimobrian/GraphQL-Express: An Express Server implemented using GraphQL下载了代码,以消除我出错的可能性。但是,我仍然遇到同样的错误。
我认为最好提供指向 repo 的链接而不是在此处粘贴代码,因为我使用的是 repo 中的相同代码。另外,我不确定哪个文件可能包含问题。
$ npm start
> tutorial-server@1.0.0 start kimobrian/GraphQL-Express.git
> nodemon ./server.js --exec babel-node -e js
[nodemon] 1.18.9
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `babel-node ./server.js`
GraphQL Server is now running on http://localhost:7700
错误是http://localhost:7700/graphql 在浏览器中缺少GET 查询。在 Firefox 和 Chromium 中也是如此。
更新:我在相关信息中找到的唯一问题是:nodejs with Graphql。建议的解决方案是
server.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
}));
但是,这正是我已经拥有的代码(来自教程)。这是我的全部server.js:
import express from 'express';
import cors from 'cors';
import {
graphqlExpress,
graphiqlExpress,
} from 'graphql-server-express';
import bodyParser from 'body-parser';
import { schema } from './src/schema';
const PORT = 7700;
const server = express();
server.use('*', cors({ origin: 'http://localhost:7800' }));
server.use('/graphql', bodyParser.json(), graphqlExpress({
schema
}));
server.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql'
}));
server.listen(PORT, () =>
console.log(`GraphQL Server is now running on http://localhost:${PORT}`)
);
【问题讨论】:
-
检查你的包版本。看来您的软件包名称已更改为 require('apollo-server-express') npmjs.com/package/graphql-server-express。用这个在 Express 上集成 GraphQL graphql.org/graphql-js/running-an-express-graphql-server
标签: node.js express graphql apollo apollo-server