【发布时间】:2018-11-23 16:19:33
【问题描述】:
我正在使用 graphql-tools 构建一个 GraphQL Schema,本质上我有这个结构
const typeDefs = `
type Query {
author(name: String): Author
}
interface Person {
id: Int
name: String
citizenship: String
type Author implements Person {
id: Int
name: String
citizenship: String
`
我有以下解析器
const resolvers = {
Query: {
author(_,args) {
return Author.find({where: args});
}
}
Person: {
citizenship() {
return "Example Citizenship";
}
}
}
我使架构可执行
const schema = makeExecutableSchema({
typeDefs,
resolvers,
inheritResolversFromInterfaces: true
});
和可选参数 inheritResolversFromInterfaces: true 它应该允许我根据 apollo graphql-tools 文档 (link) 继承从 Person 到 Author 的公民身份解析器。这样当查询作者时,就会出现“Example Citizenship”字符串。
然而它没有,查询返回
"author": {
"id": 1,
"name": "Peter",
"citizenship": null
}
【问题讨论】:
-
您使用的是什么版本的 graphql-tools?该功能仅在 v2.24.0 中添加
-
我刚查了一下,我运行的版本是v2.8.0,我更新到v2.24.0,现在可以用了!
-
另外,Apollo Server v2。现在支持开箱即用!
标签: graphql graphql-js