【发布时间】:2018-06-06 22:03:27
【问题描述】:
我正在使用 Apollo + Express 开始使用 GraphQL,我看到 the example 在 typedef 的底部添加了一个 schema 名称:
let typeDefs = [`
type Query {
hello: String
}
schema {
query: Query
}`];
在定义解析器后,它会生成带有makeExecutableSchema 的架构:
let schema = makeExecutableSchema({typeDefs, resolvers});
但是,如果我删除 typedef 的 schema 部分,我仍然可以正常使用我的端点,例如:
http://localhost:3000/graphql/?query={hello}
返回:
{"data":{"hello":"world"}}
但如果我将查询部分更改为其他内容,服务器将失败:
let typeDefs = [`
type Query {
hello: String
}
schema {
testquery: Query
}`];
GraphQLError:语法错误:意外名称“testquery”
我已通读Apollo's tutorial pages 和How To GraphQL tutorial for Node.js + GraphQL,但找不到对schema 部分的引用。
它是做什么用的?
【问题讨论】: