【发布时间】:2020-12-17 09:00:51
【问题描述】:
所以我的 server.js 和 schema.js 都有这个代码,来自 apollo doc 教程https://www.apollographql.com/docs/tutorial/introduction/
server.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
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
我所做的唯一调整是选择导入/导出模块的 ES 模块方法,而不是文档中使用的 commonJS 方式,我认为这不应该是一个问题,它编译时没有错误,但没有得到 graphql 操场要查看我的架构,我会收到 cannot Get /
我还没有完成解析器,但在这一点上,我相信我应该已经看到操场在行动了。根据文档
【问题讨论】:
标签: node.js express graphql apollo-server