Replies: 1 comment
-
|
I'd keep passing ctx into the helper. It's a common pattern in GraphQL because the context is request-scoped and may contain more than just the Prisma client, like auth data, loaders, or request metadata. Creating a new Prisma client inside the utility isn't ideal since it can lead to extra connections and bypass your existing context setup. If you only need the database, another option is to pass ctx.db instead of the entire context to keep the helper simpler and easier to test. 7Bit Casino offers a wide https://7bit.casinologin.mobi/ selection of slots, table games, and crypto-friendly payment options. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
NexusContextwithin this utility method without having to pass thectxfrom the resolver in to the method?From my understanding, I can extract the
PrismaClientfromnexus-plugin-prisma/clientand 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