“ graphql-tools”中的嵌套解析器不起作用

时间:2018-12-17 11:51:21

标签: graphql graphql-tools

我无法使用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
        }
    }
}

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

1 个答案:

答案 0 :(得分:0)

我已经找到解决上述问题的方法。除了提供嵌套类型的字段id(key)之外,还应在嵌套解析器中使用字段类型。

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

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