PrismaP
Prisma12mo ago
6 replies
Stephen

NestJS with Optimize not working

Hey everyone! I am currently looking to add Optimize to my NestJS app. Can you guys help me out figuring out why I am not receiving anything in my optimize?

I am using the following libraries and version:
- "@prisma/client": "^6.4.0",
- "prisma": "^6.4.0",
- "@prisma/extension-optimize": "^1.1.4",
- "@prisma/instrumentation": "^6.4.0",

I know I don't have to use the preview anymore in my prisma schema.

Here is my prisma.service.ts:
import {
  Global,
  Injectable,
  OnModuleDestroy,
  OnModuleInit,
} from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { withOptimize } from '@prisma/extension-optimize';

@Global()
@Injectable()
export class PrismaService
  extends PrismaClient
  implements OnModuleInit, OnModuleDestroy
{
  constructor() {
    super();
    this.$extends(
      withOptimize({ apiKey: process.env.PRISMA_OPTIMIZE_API_KEY! }),
    );
  }

  async onModuleInit() {
    await this.$connect();
  }

  async onModuleDestroy() {
    await this.$disconnect();
  }
}
Was this page helpful?