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!)
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.
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 theid
this way. If I would use the.mongooseResolvers.findById()
query, theid
would be an argument - which does not work asid
is in context.I came up with this solution (and it works!)
but I feel like there is a better, more scalable version - if I want to implement
userUpdateByIdSelf
anduserDeleteByIdSelf
I would basically have the same code 3 times over.Do you have any recommendations for this?