实现接口的 Graphql 对象不是从接口继承解析器
Graphql Object that implements an Interface is not not inheriting resolver from Interface
我正在使用 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 它应该允许我继承公民身份解析器从 Person
到 Author
,基于 apollo graphql -工具文档(link)。这样,当查询作者时,将出现 "Example Citizenship" 字符串。
然而它并没有,查询 returns 与
"author": {
"id": 1,
"name": "Peter",
"citizenship": null
}
已解决,功能inheritResolversFromInterfaces: true
是在v2.24.0版本中添加的,需要有该版本才能使用该功能。
我正在使用 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 它应该允许我继承公民身份解析器从 Person
到 Author
,基于 apollo graphql -工具文档(link)。这样,当查询作者时,将出现 "Example Citizenship" 字符串。
然而它并没有,查询 returns 与
"author": {
"id": 1,
"name": "Peter",
"citizenship": null
}
已解决,功能inheritResolversFromInterfaces: true
是在v2.24.0版本中添加的,需要有该版本才能使用该功能。