graphql-compose / graphql-compose/graphql-compose-mongoose
Missing fields from projection in addRelation
- Dominant language
- TypeScript
- Stars
- 706
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
Hi!
I'm having issues with the addRelation function. More specifically when projecting fields towards the graphql request. Worth noting is that this worked with the use of composeWithMongoose function previously.
Setup:
graphql-compose: "^9.0.3"
graphql-compose-mongoose: "^9.6.0"
mongoose: "5.13.8"
Code:
```
export const PrevisitSchema = new Schema(
{
project_id: { type: Schema.Types.ObjectId, required: true },
// ...
},
{
collection: 'previsits',
}
)
export const Previsit = mongoose.model('Previsit', PrevisitSchema)
export const PrevisitTC = composeMongoose(Previsit)
PrevisitTC.addRelation('project', {
resolver: () => ProjectTC.mongooseResolvers.dataLoader({ lean: true }),
prepareArgs: {
_id: source => source.project_id || null,
},
projection: { project_id: 1 },
})
```
To further clarify.
```
query {
previsitMany {
project_id
project {
_id
}
}
}
```
Works while:
```
query {
previsitMany {
project {
_id
}
}
}
```
does not
All that I get from source is the field __id_ and it all results in that the project field is null. Any other field I query is undefined. Any ideas to why?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.