graphql-compose / graphql-compose/graphql-compose-mongoose
Projection on addRelation not working for Discriminators
- Dominant language
- TypeScript
- Stars
- 706
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
I have a discriminator called `BProduct` which is a discriminator off the base of `AProduct`. And this discriminator has a property I'm trying to add a relation to:
```
BProductTC.getFieldOTC("metadata").addRelation(
"amenities",
{
resolver: () => AmenityTC.mongooseResolvers.findByIds(),
prepareArgs: {
_ids: (source: any) => source.amenities ?? [],
sort: null,
limit: null,
},
extensions: { projection: { amenities: true } }, <-- This doesn't work
}
);
```
However the projection on this discriminator (`BProduct`) doesn't work at all regardless of if I use extensions or not.
The below relation on the base model of `AProduct` works perfectly with the use of extension though:
```
AProductTC.addRelation("tags", {
resolver: () => TagTC.mongooseResolvers.findByIds()
prepareArgs: {
_ids: (source) => source.tags,
sort: null,
limit: null,
},
extensions: { projection: { tags: true } }, <-- works as projection should
});
```
Does anyone have a solution for adding relations on discriminator properties?
These are my dependancies:
```
"graphql": "^16.8.1",
"graphql-compose": "^9.0.10",
"graphql-compose-mongoose": "^10.0.0",
"mongodb": "^6.2.0",
"mongoose": "^8.2.0",
```
_Originally posted by @danimayfield in https://github.com/graphql-compose/graphql-compose-mongoose/issues/377#issuecomment-2023124409_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.