Still unable to get Optimize working in my NestJS app.
Hi everyone. I would really like to try Optimize, and have been trying for some time. See similar discussion here https://discord.com/channels/937751382725886062/1270167207204356178/1275034014025121792
But it does not record anything. There is not a single log. No "errors" logs, no "success" logs. I don't know what's going on. Did Optimize initialize successfully ? Did it error ?
Again, using NestJS. Here is current non-working code :
Is there a method to know which middlewares have been added ? like
this.prisma.listActiveMiddlewares()
or something ? So that I could troubleshoot, debug, try things to know where the problem comes from ? Like does it come from my implementation or from Prisma, or from the Class ?
Cheers.16 Replies
Hey @Virgile!
I was able to reproduce this issue with a NestJS project and have already reported it to Optimize team.
Here's a related thread where I shared the reproduction:
https://discord.com/channels/937751382725886062/1288624617165946943/1288624617165946943
I'll provide you with an update this week with next steps. If it's a bug with Optimize, then we will work on fixing it. If it's not a bug, we will update the documentation with steps on using Optimize with NestJS.
Thank you for your patience and assistance while we work on finding the solution 🙏
@Virgile We were able to make Optimize work with Optimize. Can you instantiate PrismaClient in
OnModuleInit
like this:
https://github.com/nurul3101/Optimize-NestJS/blob/main/src/prisma.service.ts
This would make sure that queries are displayed in Optimize Dashboard.
@Virgile Just checking if you had a chance to try out the suggested solution. Let us know in case you still observe any issues.Hey, I'm trying to instantiate it like this due to typescript typings but still no luck
I'm on a monorepo if that helps
What happens if you temporarily remove the pagination extension and only use the optimize one. Do you still see no queries in optimize dashboard?
@Nurul (Prisma) I have also facing the same issue on my backend, I am using Nest.js, Prisma and swagger.
This is my databaseService code
I'm getting the log that
see your optimize dashboard
but not getting anything in the prisma optimize dashboard when running the api's in the swagger.@Anubhav@12 Do you mind sharing link to your repository?
I would like to share it with our Optimize team
Its a private repo but i will try to make a reproducible example of this repo in a public repo then i will share the link
That would be very helpful 🙏
Hi @Nurul (Prisma) . Got the same issue as @Anubhav@12 on my main monorepo.
On a repro monorepo, it does show the data (when calling prisma inside the prisma service, after extending Optimize)
Here is the repro.
Check the Loom : https://www.loom.com/share/ba72e31200d447528d5700289f07ef0d
Github Repo : https://github.com/Varkoff/remix-nestjs-monorepo/tree/feature/prisma-optimize (on
feature/prisma-optimize
branch)
If you install this repo, you will have to create the .env file in the root folder and the backend folder.
Also pinging you @Marc Hess because you asked me how you could help with Optimize. This is how 🙂Loom
Optimize Usage in Monorepo with NestJS and Linux 🚀
Hello team! In this video, I demonstrate how I utilize Optimize in a Monorepo using NestJS and Linux. I showcase integrating Prisma service, making database calls, and troubleshooting API call detection issues. No specific action requested from viewers.
GitHub
GitHub - Varkoff/remix-nestjs-monorepo at feature/prisma-optimize
Remix App With NestJS Adapter. Contribute to Varkoff/remix-nestjs-monorepo development by creating an account on GitHub.
@Virgile Thank you so much for taking the time to share the repository and the loom recording with us. I am sharing it with our Optimize team to get insights on why queries are not showing up in a monorepo setup 🙏
Hey @Virgile thanks for your reproduction, it was really helpful. We uncovered a bug for which I have built a fix for.
Before we release it, I just want to make sure that everything works as expected. Here are some changes you'll need to make:
1. Install the development version to try it out (make sure not to include any caret in the version
^
):
2. Remove Object.assign
workaround, as in my tests it does not work as described. Instead to this:
You will need this workaround until https://github.com/prisma/prisma/issues/18628 is implemented.
This drawback specifically impacts Nest.js. With the workaround, full type safety should be preserved.
We will likely release this fix early next week, in the mean time let me know if you have any feedback.
I don't have a timeline, however, on the specific issue I have linked above.
Thanks! Feel free to reach out if you have any questions
Hey @Virgile I just wanted to let you know we have released the fix.Thank you man. Was looking forward to it 🙂
You have released it ? I don't see an updated Prisma version yet
Using version
"@prisma/extension-optimize": "^1.0.3"
Hey @Virgile apologies for the late reply. There was a compounded issue that we didn't account for, specific to Nest.
I have tried it within your project and was able to record queries. You'll need to update to the latest version.
Thanks for the reply ! I’ve stopped using NestJS on the company project, very excited about trying Prisma Postgres with all these features builtin