graphql-compose / graphql-compose/graphql-compose-mongoose

Missing fields from projection in addRelation

Open
#377 12 comments 0 reactions 0 assignees View on GitHub
bug
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.