reactjs - 如何使用graphQL父参数
问题描述
我已经在根查询中创建了 LogEvents 字段,但我不确定如何在子文件中使用父参数请确保这一点。最好的
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
LogEvents: {
type: new GraphQLList(LogEvent),
args: { DeviceID: { type: GraphQLInt } },
resolve(parent, args) {
return getEventListByDeviceID(args.DeviceID)
}
}
}
})
解决方案
这很好用
const LogEvent = new GraphQLObjectType({
name: 'LogEvent',
fields: {
EventAttribute: {
type: EventAttribute,
resolve(parent, args) {
return getEventAttributesByEventID(parent.EventID)
}
}
}
})
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
LogEvents: {
type: new GraphQLList(LogEvent),
args: { DeviceID: { type: GraphQLInt } },
resolve(parent, args) {
return getEventListByDeviceID(args.DeviceID)
}
}
}
})
推荐阅读
- azure - 如何阻止出站 HTTP 连接超时
- cakephp - CakePhp3.7 插件自动加载选项不可用
- windows - 如何有条件地播放 Beep?
- javascript - 处理有效的模态解雇和真正的异常
- javascript - 尝试访问 SVG 元素时,getElementById 返回 null
- android - 名为“debug-x86”的变体,但仅找到名为“”的变体
- c# - 由于处理器体系结构不匹配,MSBuildWorkspace.OpenSolutionAsync(solutionPath) 无法编译
- hibernate - jpql "join fetch" vs EntityGraph
- jquery - 如何防止 JQuery 动画中的错误
- javascript - Javascript画布绘图 - 形状已填充