我有2个查询。我想将查询包装在“仪表板”中,在其中可以将ID传递给它。目前,我必须为每个查询传递一个id变量。因此,目标是能够查询=>
{
dashboard(id: "27839703890"){
transferCount
leadCount
}
}
这是我的查询:
export const queries = {
transferCount: {
type: GraphQLInt,
args: {
id: { type: new GraphQLNonNull(GraphQLString) },
},
resolve: TransferCountResolver,
},
leadCount: {
type: GraphQLInt,
args: {
id: { type: new GraphQLNonNull(GraphQLString) },
},
resolve: LeadCountResolver,
},
}
这是解析器的外观:
const LeadCountResolver = (parent, args) => {
return Transfer.countDocuments({
account: ObjectID(args.id),
updatedAt: {
$gte: new Date('2019-02-07'),
},
dial_logs: {
$not: { $size: 0 },
},
})
}