如何实现根查询,将变量传递给子代

时间:2019-02-08 13:38:26

标签: javascript node.js graphql

我有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 },
    },
  })
}

0 个答案:

没有答案