I have a collection called 'assignments' that is like below:
[
{
"_id" : ObjectId("60e1d5824a5b1c32c069c864"),
"course" : ObjectId("5ffeec372b2234556439d1da"),
"students" : [
{
"_id" : ObjectId("60e1d5824a5b1c32c069c865"),
"user" : ObjectId("601e489fb77a9fabf85ea306"),
"section" : ObjectId("6002fae3e58bc750b4394229")
},
{
"_id" : ObjectId("60e1d5824a5b1c32c069c866"),
"user" : ObjectId("601e48cdb77a9fabf85ea307"),
"section" : ObjectId("6002fae3e58bc750b4394229")
}
]
},
{
"_id" : ObjectId("60e1c8a6a2886142b8b86523"),
"students" : [
],
"course" : ObjectId("5ffeec372b2234556439d1da"),
}]
Here you see an array named "students". I want to get details of "user" and "section" while querying the "assignments".
I am using graphql. And 'students' is a field of the type 'Assignment' like below:
type AssignmentStudent{
user:User
section:Section
}
type Assignment{
id:ID!
createdAt:Date
updatedAt:Date
course:Course!
students:[AssignmentStudent!]
}
When I query I get information of 'course', but for 'students' I am not sure what to do.
In 'Assignment' resolver I have written query for 'course' like this:
Assignment: {
async course(parent, { input }, context, info) {
try {
return await Course.findById(parent.course)
} catch (err) {
console.log('err', err.message);
}
}
}
For actual result of 'stuents' what should I do ?