【问题标题】:Graphql Object that implements an Interface is not not inheriting resolver from Interface实现接口的 Graphql 对象没有从接口继承解析器
【发布时间】: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) 继承从 PersonAuthor 的公民身份解析器。这样当查询作者时,就会出现“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


【解决方案1】:

已解决,inheritResolversFromInterfaces: true 功能是在 v2.24.0 版本中添加的,需要该版本才能使用该功能。

【讨论】:

    猜你喜欢
    • 2022-10-07
    • 1970-01-01
    • 2022-10-24
    • 2016-09-12
    • 2023-03-13
    • 2016-10-23
    • 2011-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多