嵌套查询返回空数组

时间:2018-06-05 08:28:50

标签: meteor graphql apollo

我想通过一个id为456d456d67exa的嵌套数组作为我们的例子并获取Car Name,之后通过发件人列表找到具有id的用户并获取emails.address& profil.name 此刻我得到一个空数组

Car.json:

{
    "_id": "456d456d67exa",
    "Name": "Apollo",
    "senders": [
        "zAxNarwAE2AnvPb8P",
        "Kz65arwAE2AnvPb8P",
        "Walaik56YDvWMShKY",
        "f2HA9Xc9hJNRuL5cp"
    ],
    "version": "4.2.0",
    "hardware": "5",
}

我要获取电子邮件的"_id": "zAxNarwAE2AnvPb8P",文件的例子.adress + profile.name

{
    "_id": "zAxNarwAE2AnvPb8P",
    "createdAt": {
        "$date": "2018-04-16T09:45:10.212Z"
    },

"emails": [
    {
        "address": "Jean@paul.com",
        "verified": false
    }
],
"profile": {
    "features": {
        "pictures": false
    },
    "name": "Jean-Paul"
},
}

我想在表格中加入CarName +发件人(电子邮件+姓名)

这是我的car.type文件

import {
  GraphQLString,
  GraphQLObjectType,
  GraphQLInt,
  GraphQLList,
} from 'graphql'
import { GraphQLSchema } from 'graphql';
import userType from '../user/user.type';

const carType = new GraphQLObjectType({
  name: 'Car',
  fields: () => ({
    _id: {
      type: GraphQLString,
      description: 'ID of the car'
    },
    idSender:{
      type: new GraphQLList(GraphQLString),
      description:'List of all senders'
    },
    UserList: {
       type: new GraphQLList(userType) 
    },
    name: {
      type: GraphQLString,
      description: 'Name of the car'
    },

  }),
    })
export default carType

这是我的user.type

import {
  GraphQLString,
  GraphQLObjectType,
  GraphQLInt,
} from 'graphql'

const userType = new GraphQLObjectType({
  name: 'User',
  fields: () => ({
    firstname: {
      type: GraphQLString,
      description: 'User\'s first name'
    },
    email: {
      type: GraphQLString,
      description: 'User\'s email address'
    },
  }),
})

export default userType

这就是我想要做的事情,但我得到一个空阵列,我很确定我做错了什么

 GetInfo: {
    type: new GraphQLList(Car),
    resolve: async (_, args, { userId }) => {
      if (!userId) {
        throw new Meteor.Error(401, 'Unauthorized');
      }
      const userIterable = []
      await Cars.find({ senders: userId })
      .forEach((car) => {
         Meteor.users.find({
          UserList:'emails.address',? //( i want to get the emails.address + profile.firstname)
          // email:'emails.address'
        }).forEach((usr)=>{
          userIterable.push(usr)
        })

      })
      return userIterable
    }
  }

0 个答案:

没有答案
相关问题