首页 > 解决方案 > 如何使用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)
        }
    }
}

})

标签: reactjs

解决方案


这很好用

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)
         }
     }
 }
 })

推荐阅读