W
Wasp•7mo ago
Estelle

Is it possible to use prisma clientExtensions?

10 Replies
kapa.ai
kapa.ai•7mo ago
Hi @Estelle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, it is possible to use Prisma's "client extensions" feature with Wasp. This feature replaces the deprecated Prisma client middleware. Wasp currently uses Prisma middleware for certain operations, such as hashing user passwords. However, there is an open issue on Wasp's GitHub to migrate to the latest version of Prisma and utilize the "client extensions" feature for these operations. Please note that this is an ongoing development and might not be available in the current stable release of Wasp. You can follow the progress on this issue here (https://github.com/wasp-lang/wasp/issues/1281). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Estelle, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Estelle
EstelleOP•7mo ago
So I can't use it myself for the moment?
martinsos
martinsos•7mo ago
@Elijah Elkins that is an intersting question! Ok, so what you want to do is register some client extension on Prisma client. Wasp has its own instance of prisma client that it sends around when you are using entities, but you can also import Prisma directly with import ... from '@prisma/client'. I have to refresh my memory though, is that all the same instance of prismaClient, a singleton? If so, that is great, you could just import this one in serverSetup function, register clientExtensions, and they would be applied. But if it is not a singleton then you need to specifically get to the prisma client that Wasp uses internally and I don't think we make that available in serverSetup function (we probably should then!). @miho I think you will know this better than me, what do you think?
miho
miho•7mo ago
Using Prisma client extensions requires you to replace the Prisma client instance Wasp uses (if you want to get the Prisma client with the extensions your wrote), which we don't support for now. Ideally, we would have a hook called setupPrisma: (prisma: PrismaClient) => PrismaClient that would enable you to do this thing. Nothing is stopping you to have your own "special" Prisma client instance that you use around the codebase for some specific queries you want to abstract away. But then the Prisma client the Wasp uses and exposes would stay the same of course.
martinsos
martinsos•7mo ago
Hm that sucks a bit! @miho should we just give them access to Wasp's prismaClient in server setup function? That sounds like a good way to support this, what do you think? Instead of having a separate hook.
miho
miho•7mo ago
Users already have access to the Prisma client that's not the issue. Users need to modify the Prisma client and then Wasp has to use their instance. It's an inmutable change:
About Prisma Client extensions
When you use a Prisma Client extension, you create an extended client. An extended client is a lightweight variant of the standard Prisma Client that is wrapped by one or more extensions. The standard client is not mutated. You can add as many extended clients as you want to your project. Learn more about extended clients.
Estelle
EstelleOP•7mo ago
@miho ok so for the moment I'll find another way thank you
martinsos
martinsos•7mo ago
Ah so it is inmutable! Ok, wasn't aware of that. Right we do need a hook for this then. @miho can you open an issue for this please?
miho
miho•7mo ago
I've mentioned this hook in the hooks RFC recently 🙂 it was on a short list of what to implement next. I'll create an issue for this and the login hooks as well.
miho
miho•7mo ago
GitHub
Prisma setup hook · Issue #2116 · wasp-lang/wasp
Prisma supports client extensions: https://www.prisma.io/docs/orm/prisma-client/client-extensions which for: You can use Prisma Client extensions to add functionality to your models, result objects...
Want results from more Discord servers?
Add your server