现在看了很多遍文档,但我想我还不明白。我有以下(简化)定义:
type executive {
executiveName: String,
office: [office]
}
type office {
officeName: String,
}有可能有很多(数千)的办公室可以被归还,所以我想把主管和办公室之间的电话分开,这样我就可以先向主管展示并在后台加载办公室。我这样称呼我的API:
query {
executives {
executiveName
office {
officeName
}
}
}问题1:这种分层结构是否适用于这种情况?有什么更好的方法可以建议我构造我的查询呢?
我还有以下解析器:
const queryType = new GraphQLObjectType({
name: "Query",
description: "Query entry point for the application",
fields: () => ({
executives: {
type: GraphQLList(executives),
resolve: (_, __, { dataSources }) => {
return dataSources.elasticAPI.getExecutives();
}
},
{
office: {
type: office,
name: "office",
resolve: async (_, { startDate, endDate }, { dataSources }) => {
const offices = await dataSources.elasticAPI.getOffices(
startDate,
endDate
);
return offices
}
}
})
})
})但得到以下答复:
{
"data": {
"executives": [
{
"executiveName": "Joe Smith",
"office": null
}
...
]
}
}问题2:为什么我的解析器返回null?我原以为办公室解析器会返回信息,但GraphQL没有识别。
发布于 2021-08-13 22:03:40
为什么我的解析器返回
null?我原以为办公室解析器会返回信息,但GraphQL没有识别。
您在所需模式中显示的office字段是executive类型的一部分,而不是Query类型的一部分。解析器对象需要反映这一点。
https://stackoverflow.com/questions/68778222
复制相似问题