How do you manage the Prisma Client in Express and NestJS, GraphQL (Not Next.js) ??
We are using GraphQL with Apollo Server and injecting the Prisma Client into the resolver’s context.
However, this approach requires passing the Prisma Client to service classes within the resolver. As the depth increases, the need to pass Prisma throughout the application becomes more frequent.
It seems better to use a singleton and import the Prisma Client directly in the service class, as described in the article below.
How do you manage the Prisma Client in your projects ?? 🤔
https://github.com/prisma/prisma/issues/5139
GitHub
For those having this issue, I solved it by creating a singleton:...
For those having this issue, I solved it by creating a singleton: import { PrismaClient } from '@prisma/client' class DBClient { public prisma: PrismaClient private static instance: DBClien...
2 Replies
You're in no rush, so we'll let a dev step in. Enjoy your coffee, or drop into
#ask-ai
if you get antsy for a second opinion!Hey 👋
Did you had a chance to look at this example?
https://github.com/prisma/prisma-examples/tree/latest/orm/nest-graphql
GitHub
prisma-examples/orm/nest-graphql at latest · prisma/prisma-examples
🚀 Ready-to-run Prisma example projects. Contribute to prisma/prisma-examples development by creating an account on GitHub.