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
Preview feature feedback: Prisma Client Extensions #16500
Comments
Useful feedback? I'm taking half a day just to ponder the implications of this giant leap forward. 🤩 |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@ymc9 at the moment it is not possible for interactive transactions. Could you describe your usecase in more detail? Maybe we could suggest a workaround |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Thanks for the reply, @SevInf . I'm working on a toolkit (https://zenstack.dev) that extends Prisma with authorization-related stuff. The way I did it before was by generating a wrapper around PrismClient and injecting authorization conditions into queries there. I'm excited to see custom queries extension because it has the potential to solve the problem more elegantly. Unfortunately, for some of the situations, I needed to use interactive transactions to "try" proceeding with an operation and then revert it afterward. That's why I'm asking for interactive transaction support. Pseudo code: prisma.$extends({
query: {
myModel: {
async update({ args, query }) {
prisma.$transaction(async() => {
inject(args);
const r = await query(args);
if (validate(r)) {
throw new Error('rejected');
}
return r;
});
},
},
},
}); The extension mechanisms look really cool. Thank you! |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
Suggested API change to make things more self-explanatory and reduce potential for confusion:
(Which would essentially do the same as Currently: https://www.prisma.io/docs/concepts/components/prisma-client/client-extensions/client#example client: {
...
async $totalQueries() {
// Prisma.getExtensionContext(this) in the following block
// returns the current client instance
... await Prisma.getExtensionContext(this).$metrics.json() vs. imagine if we could write: client: {
...
async $totalQueries() {
... await Prisma.getExtendedClient(this).$metrics.json() // `ctx` refers to the current model
const ctx = Prisma.getExtensionContext(this)
// `ctx.name` returns the name of the current model
console.log(ctx.name) vs. imagine if we could write: const modelName = Prisma.getExtendedClientModel().name Context / how I reached this suggestion(Sharing in case the context is useful but leads you to a different conclusion vs. the suggestion above!) I really struggled to understand the function and intended "job" of It finally clicked when I looked up the implementation of Even then, I didn't fully understand the 2 different use cases for I initially consisting suggesting a simple rename Another gotcha this would resolve is confusing the purpose of I initially considered suggesting a rename Also worth calling out in the docs how when overriding queries using |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as duplicate.
This comment was marked as duplicate.
@beacoding could you please create a new issue with some level detail for us to be able to reproduce it? |
@tacomanator @dodas @linjer I don't think this could be easily done at the moment. However, we have thought about introducing custom serializers/deserializers in the future and have an internal issue tracking this. |
@whygee-dev This is a limitation of client extensions, they happen at runtime, not at the database level. This is similar to what @johnkm516 proposed in #16500 (comment). @johnkm516 could you please open a feature request? |
Thanks @jackpordi @AndresRodH @jakeleventhal @aniravi24 @Faithfinder @alizahid for the feedback. We are now tracking your suggestions in an internal issue. |
@dhmoon91 @SorenHolstHansen while your example is lacking async/await, you should be able to have working types. We have an issue about lower cased models causing type issues, could it be that? If not, can you please create a new issue? |
Hey @jansedlon, @Toinouze, @zackdotcomputer, @ostkrok and Nest users, we have a tracking issue for this over here #18628. Let us know what you think. @Mahi would this solve your use-case in combination with advanced type-safety helpers. |
thanks @millsp! I did something similar a few moths back, but haven't used it much (was more for users of Pothos than for something I needed myself). That totally works, and prefixing with |
@SamuelMS please use the |
@DylanNWatt You can use Prisma.defineExtension in combination with a factory/constructor pattern. Something like:
I created an internal issue to improve the docs. |
There already is an existing issue #3102 |
Thanks everyone, Client Extensions are Generally Available since 4.16.0 🥳 |
Please share your feedback about Prisma Client Extensions released in v4.7.0 in this issue.
If you encounter a bug, please open a bug report in this repo.
If the feature is working well for you, please share this in a comment below or leave a 👍 on this issue.
If you have any questions, don't hesitate to ask them in the #prisma-client channel in the Prisma Slack.
The text was updated successfully, but these errors were encountered: