graphql-compose / graphql-compose/graphql-compose-mongoose
Get user information of currently logged in user
- Dominant language
- TypeScript
- Stars
- 706
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
I want to have a query that displays me all the information of the currently logged in user.
I use JWT for log in that stores the id in `context` and can get the `id` this way. If I would use the `.mongooseResolvers.findById()` query, the `id` would be an argument - which does not work as `id` is in context.
I came up with this solution (and it works!)
```js
UserTCPublic.addResolver({
kind: 'query',
name: 'userSelf',
description: "execute user query on currently logged in user",
type: UserTCPublic.mongooseResolvers.findById().getType(),
resolve: async ({context}) => {
return User.findById(context.req.user._id);
}
})
```
but I feel like there is a better, more scalable version - if I want to implement `userUpdateByIdSelf` and `userDeleteByIdSelf` I would basically have the same code 3 times over.
Do you have any recommendations for this?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.