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

[Feature Request] Make Prisma extensions "usable" #1724

Open
LilaRest opened this issue Sep 21, 2024 · 0 comments
Open

[Feature Request] Make Prisma extensions "usable" #1724

LilaRest opened this issue Sep 21, 2024 · 0 comments

Comments

@LilaRest
Copy link

Is your feature request related to a problem? Please describe.

Prisma introduces the concept of “Extensions”, which enable the insertion of custom business logic before a query is sent to the database.

On paper, this idea is fantastic, as it opens doors to various functionalities such as “soft deletes,” “custom identifiers,” “row-level logging,” and more.

However, the current implementation of Prisma extensions faces a significant challenge: they fail to parse nested queries, as exemplified by the following code snippet:

await db.user.create({
  data: {
    name: “John”,
    memberships: {
      create: {  // Nested create here, which won’t be parsed by the extension
        ()
      }
    }
  }
})

This limitation poses a problem because many scenarios cannot afford to parse only the top-level queries. For instance, imagine a logging system that doesn’t log nested queries or a soft-delete system that hard deletes nested queries 😅

Consequently, people are not utilizing extensions.

Describe the solution you'd like.

Given that ZenStack already parses Prisma queries to enforce access policies, and that the Prisma team doesn't seem to prioritize this issue, I believe it would be an ideal place to propose a new and safer approach to extensions.

We could envision a simple API, quite similar to the Prisma Extensions API, that would allow us to define custom logic for specific events, such as “create” for a “User” entity. For example:

const db = enhance(prisma, )
  .$on(“create”, “User”, (args, query) => {
    // (…) Custom logic here to modify ‘args’
    return query(args)
  })

I've seen this idea mentioned in the past, I wanted to open this issue as a way to deeply explore all the intricacies of this idea, possibly leading to an implementation.

Additional context.

References: #20554

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

1 participant