P
Prisma•4mo ago
dennemark

Client Extension - when is query called?

Hi, I am developing a client extension and want to filter data after i have used my query. I.e. I could do the following:
$allModels: {
findUnique({args, query}){
return query({...args, foo: "bar"}).then((queryResults)=> queryResults.filter((x)=>x))
}
$allModels: {
findUnique({args, query}){
return query({...args, foo: "bar"}).then((queryResults)=> queryResults.filter((x)=>x))
}
Is this legit? I am wondering, because client extensions can be chained. So the next extension would get the args and query, but they would not fire, right?
3 Replies
Nurul
Nurul•4mo ago
Hey, I believe this should work. But, I would need to reproduce this to confirm. Have you looked at these examples, some of the usecases are similar to what you want to achieve: https://github.com/prisma/prisma-client-extensions/tree/main
GitHub
GitHub - prisma/prisma-client-extensions: Examples of Prisma Client...
Examples of Prisma Client extensions. Contribute to prisma/prisma-client-extensions development by creating an account on GitHub.
dennemark
dennemarkOP•4mo ago
@Nurul (Prisma) thanks for your reply! yes it seems to work! i think this one is a good example and it also seems to be working in my case. https://github.com/prisma/prisma-client-extensions/blob/03a45bdf777fe31591fb1c33568d22731af334dd/input-validation/src/index.ts Am developing a client-extension that integrates CASL in a very convenient way. https://github.com/dennemark/prisma-extension-casl
GitHub
prisma-client-extensions/input-validation/src/index.ts at 03a45bdf7...
Examples of Prisma Client extensions. Contribute to prisma/prisma-client-extensions development by creating an account on GitHub.
GitHub
GitHub - dennemark/prisma-extension-casl: Enforce casl abilities on...
Enforce casl abilities on prisma client. Contribute to dennemark/prisma-extension-casl development by creating an account on GitHub.
Nurul
Nurul•4mo ago
I am glad to hear that it's working as expected! 😄
Want results from more Discord servers?
Add your server