Ability to extend `PrismaClient` class w/ Client Extensions before instantiation
## Problem Within NestJS, the common solution to implementing an injectable Prisma Client instance is to extend `PrismaClient` and add the `onModuleInit` and `enableShutdownHooks` functions required by NestJS. This typically looks like: ```ts import { Injectable, OnModuleInit, INestApplication } from '@nestjs/common' import { PrismaClient } from '@prisma/client' @Injectable() export class PrismaService extends PrismaClient implements OnModuleInit { async onModuleInit() { await this.$connect() } async enableShutdownHooks(app: INestApplication) { this.$on('beforeExit', async () => { await app.close() }) } } ``` You can use `clientExtensions` to add these functions, however, they can not adjust the type of `PrismaClient` and this scenario requires you to export a properly typed, uninstantiated class for NestJS to use. An example of adding the functions is below: ```ts const prisma = new PrismaClient().$extends({ client: { async onModuleInit() { await Prisma.getExtensionContext(this).$connect(); }, async enableShutdownHooks(app: INestApplication) { Prisma.getExtensionContext(this).$on('beforeExit', async () => { await app.close(); }); }, }, }); ``` ## Suggested solution Add a static method to `PrismaClient` that is available when using the `clientExtensions` preview features that allows you to add methods to the class (and adjust the type) before instantiation. This resulting class describe above wo
Posted by sabinadams on Apr 4, 2023, 9:19 PM
Tags
Related issues
- 2026 - Microsoft Office 365
- [Ubuntu] `ubuntu-latest` label will use Ubuntu 26.04 in November 2026
- Gamut mapping
- [Codex Desktop] Editing and resending a queued message triggers "App-server queued follow-up no longer exists"
- [Windows] ChatGPT 26.820.60940 fails with "invalid transport in mcp_servers.codex_app"; Beta 26.727.40816 works
- [BUG]: infinite loading of videos
Raise real-world problems, find people facing the same issue, and discuss solutions.2,500 issues0 comments
github (SaaS)
2026 - Microsoft Office 365
[Ubuntu] `ubuntu-latest` label will use Ubuntu 26.04 in November 2026
Gamut mapping
[Codex Desktop] Editing and resending a queued message triggers "App-server queued follow-up no longer exists"
[Windows] ChatGPT 26.820.60940 fails with "invalid transport in mcp_servers.codex_app"; Beta 26.727.40816 works
[BUG]: infinite loading of videos
Restore GPT-5.6 Sol’s 372k Codex context window, or provide an opt-in setting
Codex Desktop for macOS repeatedly triggers `syspolicyd` / `trustd` CPU and memory runaway
Ability to extend `PrismaClient` class w/ Client Extensions before instantiation
## Problem Within NestJS, the common solution to implementing an injectable Prisma Client instance is to extend `PrismaClient` and add the `onModuleInit` and `enableShutdownHooks` functions required by NestJS. This typically looks like: ```ts import { Injectable, OnModuleInit, INestApplication } from '@nestjs/common' import { PrismaClient } from '@prisma/client' @Injectable() export class PrismaService extends PrismaClient implements OnModuleInit { async onModuleInit() { await this.$connect() } async enableShutdownHooks(app: INestApplication) { this.$on('beforeExit', async () => { await app.close() }) } } ``` You can use `clientExtensions` to add these functions, however, they can not adjust the type of `PrismaClient` and this scenario requires you to export a properly typed, uninstantiated class for NestJS to use. An example of adding the functions is below: ```ts const prisma = new PrismaClient().$extends({ client: { async onModuleInit() { await Prisma.getExtensionContext(this).$connect(); }, async enableShutdownHooks(app: INestApplication) { Prisma.getExtensionContext(this).$on('beforeExit', async () => { await app.close(); }); }, }, }); ``` ## Suggested solution Add a static method to `PrismaClient` that is available when using the `clientExtensions` preview features that allows you to add methods to the class (and adjust the type) before instantiation. This resulting class describe above wo
Comments (0)
No comments yet. Start the discussion.