I want to get through a nested array with the id 456d456d67exa as our exemple here and get Car Name, after that go through the senders list and find the user with the id and get emails.address & profil.name
at the moment i get an empty array
Car.json :
{
"_id": "456d456d67exa",
"Name": "Apollo",
"senders": [
"zAxNarwAE2AnvPb8P",
"Kz65arwAE2AnvPb8P",
"Walaik56YDvWMShKY",
"f2HA9Xc9hJNRuL5cp"
],
"version": "4.2.0",
"hardware": "5",
}
Exemple of a the document of the "_id": "zAxNarwAE2AnvPb8P",
that i want to get the emails.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"
},
}
I want to get in a table the CarName + the senders ( email + name )
This is my car.type document
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
This is my 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
And this is what iām trying to do but i get an empty array iām pretty sure iām doing something wrong
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
}
}