使用此查询,在graphQL中,{
"query": "query ($requiredArg: String!, $anotherArg: String) { user(requiredArg: $requiredArg) { desiredSubfield(anotherArg: $anotherArg) { _id name} } }",
"variables": {
"requiredArg": "someString",
"anotherArg": "anotherString"
}
}
上的解析函数未被调用,查询返回null。如何正确解析嵌套字段?
查询:
export default {
type: userType,
args: {
requiredArg: {
name: 'requiredArg',
type: new GraphQLNonNull(GraphQLString),
},
fields: () => {
return {
desiredSubfield: {
type: subfieldType,
args: subfieldType.args,
resolve(source, params, root, ast) {
console.log('subfield resolve is hit');
return fetchUser();
},
},
};
},
resolve(source, params, root, ast) {
console.log('in main resolve');
}
};
相关对象:
{{1}}
答案 0 :(得分:2)
好吧,看起来我想通了(叹息)
问题是我为非嵌套字段写的虚拟解析函数没有返回。看到修复:
export default {
type: userType,
args: {
requiredArg: {
name: 'requiredArg',
type: new GraphQLNonNull(GraphQLString),
},
fields: () => {
return {
desiredSubfield: {
type: subfieldType,
args: subfieldType.args,
resolve(source, params, root, ast) {
console.log('subfield resolve is hit');
return fetchUser();
},
},
};
},
resolve(source, params, root, ast) {
console.log('in main resolve');
return true;
}
};
我会把这个留在这里以防万一其他人遇到同样的事情。