graphql-compose / graphql-compose/graphql-compose-mongoose
How to populate items in array?
- Dominant language
- TypeScript
- Stars
- 706
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
I have in mongoose document collection with an array of documents:
```
export const DocumentsCollection = mongoose.model('Document-Collection',
new mongoose.Schema({
name: { type: String },
items: [
{
name: { type: String },
documents: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Document' }],
},
],
})
);
export const Document = mongoose.model( 'Document',
new mongoose.Schema(
{
name: { type: String },
description: { type: String }
},
{ timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' } }
)
);
```
I need to do a query that returns all the objects (`findMany`) with items populated.
The problem is items returns as an array of mongoids.
How to extend the `findMany` resolver to populate document object?
This is my expected query:
```
{
documentCollectionMany {
name,
items {
name
_id,
documents
}
}
}
```
Currently I getting this results:
```
{
"data": {
"documentCollectionMany": [
{
"name": "docgroup1",
"items": [
{
"name": "cat1",
"_id": "5ca37e1d21570b0011742473",
"documents": [
"5c6c0213f0fa853bd7d4a38c",
"5c6c02948e0004a16529a1a1",
"5c6c02ee7e76c62075850119",
"5c6ef2ddd16e17889ffaffd0"
]
}
]
}
]
}
}
```
@nodkz Is it something possible to do? because I can't find any working example.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.