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

Add default values from request

Open
#33 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
706
Forks
98
PR merge metrics
No merged PRs in 30d

Description

Hello!
I use your package to compose mongoose models to GraphQL and I have a mutation that creates new Goal record:
```
mutation createGoal($name:String!){
goalCreate(record:{
name: $name
}){
record {
_id
name
}
}
}
```
Goal schema have an userId field (an id of user that created this Goal).

I don't want to pass userId from front-end due to security concern, but want to set userId in the back-end app, and get it from req.user object.

Is it possible to accomplish this with your library?
If it is, can you give me an example of how to set record field before original resolver is called?

**To be more concise:**
From front-end I send:
```json
{
"name": "New goal"
}
```
In the back-end I want to transform it to:
```json
{
"name": "New goal",
"userId": "592e6eaac21d362f2d86039a"
}
```
where *userId* - the id of currently logged in user (req.user.id field).
And pass this transformed object to createOne resolver.

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.