olivierwilkinson / prisma-extension-soft-delete

Prisma extension for adding soft delete to Prisma models, even when using nested queries
Apache License 2.0
97 stars 14 forks source link

Export logic only, without fully exporting extension definition #11

Open elie91 opened 8 months ago

elie91 commented 8 months ago

To manage row level security, I created a Prisma extension that applies logic to all operations using $allModels and $allOperations.

Now that I want to implement a soft delete system, I've installed this extension and extended my prisma client to use it.

However, as the client already uses the extension for the RLS, there's a conflict because both extensions define a logic with $allOperations, which means that only the last extension called will be taken into account.

Would it be possible to export all the logic contained in $allOperations separately, so that you can choose whether to import the complete extension (createSoftDeleteExtension) or just the logic?

Exporting only the logic would allow me to merge the code of the two extensions into a single one, in order to define the $allOperations only one time

olivierwilkinson commented 8 months ago

HI there,

Thanks for trying out the library!

I'm a little confused by the issue, when you chain extensions the last $allOperations hook is not the only one that is called, each extension's $allOperations hook is called with the query modified by the extension before. There might be some confusion if this extension is used before the RLS extension: this extension modifies the type of operation where needed so if you are logging a particular operation it might be missed. Have you tried changing the order of extensions so this extension is after the RLS, or vice-versa? Any extra information would also be helpful!

Hopefully we can figure out what is happening! 😄