【问题标题】:Nested resolver in "graphql-tools" not working“graphql-tools”中的嵌套解析器不起作用
【发布时间】:2019-05-17 18:53:40
【问题描述】:

我无法使用 graphql-tools 调用嵌套解析器。我已经在github上提交了bug,但还没有得到任何回复。

https://github.com/apollographql/graphql-tools/issues/1026.

查询时未调用我的架构的嵌套字段。

架构

type XYZ {
   title: String
}

type NestedLevel1 {
   reference: XYZ
}

type ABCD {
   title: String
   reference: XYZ
   nestedLevel1: NestedLevel1 
}

type Query {
     ABCDList(limit: Int, skip: Int): [ABCD]
}

解析器

const Resolvers = {
    Query: {
        ABCDList: () => []
    },
    ABCD: {
        reference: () => [] // this function is being called
        nestedLevel1: {
            reference: () => [] // this function is not being called
        }
    }
}

正在调用顶级“reference”的解析器函数,但不是“nestedLevel1.reference”解析器。如果我做错了什么,请纠正我。

【问题讨论】:

    标签: graphql graphql-tools


    【解决方案1】:

    我已经找到了解决上述问题的方法。在嵌套解析器中应该使用字段类型而不是提供返回类型的字段 id(key)。

    以下是对我有用的解决方案。

    const Resolvers = {
        Query: {
            ABCDList: () => []
        },
        ABCD: {
            reference: () => [] 
        },
        NestedLevel1: {
            reference: () => [] 
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-25
      • 1970-01-01
      • 2021-07-28
      • 2023-04-01
      • 2019-10-14
      • 2018-08-27
      • 2018-09-02
      • 1970-01-01
      • 2021-07-20
      相关资源
      最近更新 更多