GraphQL在第二个使用父数据合并2个Mongo调用

时间:2019-04-20 15:53:40

标签: javascript arrays graphql

我正在尝试组合/合并/缝合两个mongoDB调用,这些调用以我需要呈现数据的方式塑造了JSON响应。现在,我可以手动传递Array,请参见代码中的注释。

module.exports = {
  Query: {
    getMongoModels: async (_, args, {
      ProductId,
      MongoModel,
    }) => {

    if (!args.IsWH) {
        const models = await MongoModel.find({})
        console.log(models.length);
        console.log("ALL is met")
        return models;
          }
    }
  },
  // const docs = await ProductDocument.find({ItemID: _.ProductID})
  // I need to make a call to another collection to build this array of Documents
  // Right now the Console log Prints out all the ID's that match in a loop style fashion. so maybe i need a forEach or map function
    MongoModels: {
      Images(_, parent, args, ctx, info ) {
          console.log(_.ProductID);
          return ["1.png","2.png","3.png"];
      },
    },

}




0 个答案:

没有答案