-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Batching of findUnique()
queries fails for certain parameters
#23313
Comments
I can add that I've done some troubleshooting of the prisma client already. I found the DataLoader implementation and suspected that |
findUnique()
queries fails for certain parameters
Hey @eliasnorrby, boolean operators are not intended to work with batching. To provide further context, we have the following function: fn invalid_compact_filter(op: &Operation, schema: &QuerySchema) -> bool We use it to sort through queries and validate if they're using operations that we can't compact for batching; one of these filters is boolean operators, i.e. To ask for further context, are you specifically talking about the case of To otherwise support boolean operators, /// Those filters are:
/// - non scalar filters (ie: relation filters, boolean operators...)
/// - any scalar filters that is not `EQUALS`
/// - nativetypes (citext)
|
This has now been updated ✨ |
Thanks for clarifying @Druue! Happy to see the documentation updated. I guess this should be closed as "working as intended" then? |
Absolutely, glad we could help :) I'll be closing this now ✨ Feel free to open up a new issue as a feature request if this is something you want to see us support! |
Do you want us to add some more batching, and see a way how that could work @eliasnorrby? If so, that is definitely worth a feature request. Thanks. |
Bug description
The docs on query optimization state that
I find this is not always true, especially when
where
includes eitherOR
orAND
.Here's an example project leveraging batching of
findUnique
queries in a resolved graphql field:Changing it to
async posts(@Root() user: User, @Context() ctx): Promise<Post[]> { return this.prismaService.user .findUnique({ where: { id: user.id, + AND: [], }, }) .posts() }
results in batching not working.
Background – the real world use case
For context, we're using
@casl/prisma
to control user permissions. This means we transform a set of access rules into where args for the relevant model, so we can e.g. list all posts a user can see by implementingallPosts
something like:We're also leveraging Prisma's data loaders, which means we'll be running things like:
and this is where batching breaks down. Despite the parameters being identical, batching fails.
I've set up a reproduction repository based on the graphql nestjs example.
Video demonstration
Screen.Recording.2024-02-29.at.00.08.46.mov
How to reproduce
Expected behavior
No response
Prisma information
See reproduction repository.
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: