You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey! Quick question...I defined a helper method to request an access token from my database, then check if it is valid and return the existing token or create/return a new one. I extracted this because I have to retrieve this token several times in different resolvers. My question is, is it possible to access the NexusContext within this utility method without having to pass the ctx from the resolver in to the method?
From my understanding, I can extract the PrismaClient from nexus-plugin-prisma/client and create a new instance, however, this obviously isn't typed with my database models.
Use case:
In graphql resolver:
resolve(_root, _args, ctx) {
// i need to request the ctx in my getToken method, so I need to pass ctx here
const token = getToken(ctx);
.....
},
In util method:
const getToken = (ctx: NexusContext) {
// might be nice to do let context = new PrismaClient()?
const token = ctx.db.token.findOne({...})
.....
return token
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hey! Quick question...I defined a helper method to request an access token from my database, then check if it is valid and return the existing token or create/return a new one. I extracted this because I have to retrieve this token several times in different resolvers. My question is, is it possible to access the
NexusContext
within this utility method without having to pass thectx
from the resolver in to the method?From my understanding, I can extract the
PrismaClient
fromnexus-plugin-prisma/client
and create a new instance, however, this obviously isn't typed with my database models.Use case:
In graphql resolver:
In util method:
Beta Was this translation helpful? Give feedback.
All reactions