实现接口的Graphql对象未从接口继承解析程序
我正在使用graphql工具构建一个graphql模式,本质上我有这个结构实现接口的Graphql对象未从接口继承解析程序,graphql,graphql-js,Graphql,Graphql Js,我正在使用graphql工具构建一个graphql模式,本质上我有这个结构 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 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工具文档()将公民身份解析程序从Person
继承到Author
。这样,当查询作者时,“示例公民身份”字符串将出现
但是,如果不这样做,查询将返回
"author": {
"id": 1,
"name": "Peter",
"citizenship": null
}
已解决,功能
inheritResolversFromInterfaces:true
是在v2.24.0版本中添加的,需要该版本才能使用该功能。您使用的是哪个版本的graphql工具?该功能仅在v2.24.0I刚刚检查时添加,我运行的版本是v2.8.0,我更新为v2.24.0,现在它可以工作了!还有阿波罗服务器v2。现在支持它的开箱即用!