我有以下性质的查询
Category1(name: $cat1){
Category2(secondName: $cat2){
secondName
}}
我的架构是这样的:
const Query = new GraphQLObjectType({
name: 'Query',
fields: {
Category1: {
type: new GraphQLList(Category1Type),
args: { name },
resolve: resolveCategory1
}}
})
然后 Category1Type 定义为:
const Category1Type = new GraphQLObjectType({
name: 'Category1',
description: '<>',
fields: () => ({
name: { type: GraphQLString },
category2: {
type: new GraphQLList(CategoryType2),
args: { secondName },
resolve: resolveCategory2
}
})
});
为简单起见,假设 category2 是这样的:
const Category2Type = new GraphQLObjectType({
name: 'Category2',
description: '<>',
fields: () => ({
name: { type: GraphQLString },
})
});
现在我想使用过滤选项获取 Category1 下的所有 Category2 项目,如下所示:
Category1(name: $name){
name
category2(name: $name){
name
}}
我的解析器定义如下:
# Category1 resolver
function cat1resolve (root, args) {
return SELECT * from data WHERE category1_name = args.name
}
# Category2 resolver
function cat2Resolve (root, args) {
return SELECT * from data WHERE category1_name = rootargs.name and categort2_name = args.secondName }
现在的问题是 cat2Resolve 的“解析器”无法看到或接收 rootargs.name 来让我进行这种过滤。