[英]Apollo-server-express returning “cannot Get /” instead of the Graphql playground
so I have this code for both my server.js and schema.js from following the apollo doc tutorial https://www.apollographql.com/docs/tutorial/introduction/所以我按照阿波罗文档教程https://www.apollographql.com/docs/tutorial/introduction/为我的 server.js 和 schema.js 提供了这段代码
server.js服务器.js
import apollo from "apollo-server-express";
const { ApolloServer } = apollo;
import express from "express";
import typeDefs from "./schema.js";
const app = express();
const server = new ApolloServer({
typeDefs,
playground: true,
});
server.applyMiddleware({ app });
const PORT = process.env.PORT || 4000;
app.listen(PORT, () => {
console.log(`operating on port ${PORT}`);
})
schema.js架构.js
import pkg from "apollo-server-express"
const { gql } = pkg
// defining schema
const typeDefs = gql`
type Launch {
id: ID!
site: String
mission: Mission
rocket: Rocket
isBooked: Boolean!
}
type Rocket {
id: ID!
name: String
type: String
}
type User {
id: ID!
email: String!
trips: [Launch]!
}
type Mission {
name: String
missionPatch(size: PatchSize): String
}
enum PatchSize {
SMALL
LARGE
}
type Query {
launches: [Launch]!
launch(id: ID!): Launch
me: User
}
type Mutation {
bookTrips(launchIds: [ID]!): TripUpdateResponse!
cancelTrip(launchId: ID!): TripUpdateResponse!
login(email: String): String # login token
}
type TripUpdateResponse {
success: Boolean!
message: String
launches: [Launch]
}
`
export default typeDefs
only tweak I did was to choose the ES modules method of import/exporting modules over the commonJS way as used in the documentation, which I think shouldn't be a problem, it compiles without errors but instead of getting the graphql playground to see my schema, I get a cannot Get /
我所做的唯一调整是选择 ES 模块导入/导出模块的方法,而不是文档中使用的 commonJS 方式,我认为这应该不是问题,它编译没有错误,但不是让 graphql 操场看到我的架构,我得到一个
cannot Get /
I haven't done the resolvers, but at this point, I believe I should see the playground in action already.我还没有完成解析器,但在这一点上,我相信我应该已经看到 Playground 的运行了。 as per the docs
根据文档
When using applyMiddleware
, if you don't explicitly specify a path, it will be /graphql
by default.使用
applyMiddleware
,如果没有明确指定路径,则默认为/graphql
。
This means you'll access your endpoint and the GraphQL Playground interface at localhost:${PORT}/graphql
, not localhost:${PORT}
(which is what you're doing according to the error message).这意味着您将在
localhost:${PORT}/graphql
访问端点和 GraphQL Playground 接口,而不是localhost:${PORT}
(这是您根据错误消息执行的操作)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.