Why methods of a service not working when $use is used?
Hey Prisma community!
I'm facing a weird issue when trying to consume any methods of my service which is based on prisma service/client to make operations. For example, when I tried to get all
event sessions I got undefined (which I consider as a weird issue/behavior).
I'm using NestJs w/ Prisma (as you can see in the attached image).
I'm aware of I should use Prisma client extensions because middlewares are deprecated: the reason of described behavior (when commented, methods are working). But, it would be great if I have a deeper explanation.
3 Replies
Hi @Mohamed Lamine 👋
In your middleware logic, you specified
This logic only runs for for
create action and EventSession model. Since the middleware is only for create, it should not impact findMany. You can add logs just before the if statement in your middleware to see the action attached to params
Hello @RaphaelEtim thanks for your reply.
It seems the (bad) way I implemented it make that this middleware (
$use) is going to run every single time I do prisma.whatever.whatever i.e anytime I do a query. So it's normal for findMany to be impacted by the middleware. So I add the following line of code out of the if statement: return next(params); .
This ensure that others queries e.g findMany proceed normally when conditions are not met/satisfied.I added log as you suggested. Here it's the result:
