Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documenting Typing the Extended PrismaClient #129

Open
NGimbal opened this issue Oct 22, 2024 · 1 comment
Open

Documenting Typing the Extended PrismaClient #129

NGimbal opened this issue Oct 22, 2024 · 1 comment

Comments

@NGimbal
Copy link

NGimbal commented Oct 22, 2024

I've been running into an issue where the VSCode Typescript errors with errors like the following:

Excessive stack depth comparing types...
This expression is not callable....

After searching and consulting with various AI oracles I realized the issue could be solved by removing the prisma-field-encryption extension. This Github issue was a hint, although the discussion is from when clientExtensions were a preview feature.

prisma/prisma#17236

The solution seems to be the following:

import { PrismaClient } from '@prisma/client'
import { fieldEncryptionExtension } from 'prisma-field-encryption'
import { type PrismaClientExtends } from '@prisma/client/extension'
import type * as runtime from '@prisma/client/runtime/library'

// Define the extended client type using Prisma's extension type system
type ExtendedClient = PrismaClient & PrismaClientExtends<runtime.Types.Extensions.DefaultArgs>

const globalClient = new PrismaClient()

export const client = globalClient.$extends(
  // This is a function, don't forget to call it:
  fieldEncryptionExtension()
) as ExtendedClient

export type { ExtendedClient as PrismaClient }

Does this fix make sense? It is working nicely for me. If so I'd like to open a PR to add this to the Readme. 🙏

@franky47
Copy link
Member

Yes I think that would be a good addition, thanks!

I had to do something similar in the integration tests, though my use-case was getting the same type for a client using the middleware approach and one with the extension approach:

return client.$extends(fieldEncryptionExtension(config)) as PrismaClient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants