-
-
Notifications
You must be signed in to change notification settings - Fork 18
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: Add support for is
, isNot
relation filters
#93
Comments
Both This (removed): query {
listPosts(
where: {
author: { is: { username: "xxx" } }
}
) {
title
author { username }
}
} Is equivalent to this (supported): query {
listPosts(
where: {
author: { username: { equals: "xxx" } }
}
) {
title
author { username }
}
} Supporting both syntaxes simultaneously could be possible using the below Schema: input UserScalarsWhereInput {
# ...
author: String
}
input PostWhereInput {
# ...
author: UserWhereInput
is: UserScalarsWhereInput
isNot: UserScalarsWhereInput
} However, I'm thinking it would add (unnecessary?) complexity to detect and prevent using both syntaxes simultaneously within a single query. Unless there is a use case in which the Fluent API syntax wouldn't allow doing the same as with |
I was mostly thinking about how to check whether or not a one-to-one relationship exists. I know the equivalent would be |
Would you have an example query to share (if you were to do it with the Prisma Client directly)? |
model Valuation {
...
estate Estate?
...
}
model Estate {
...
valuationUuid String @unique
valuation Valuation @relation(fields: [valuationUuid], references: [uuid])
...
} const valuations = await client.valuation.findMany({
where: {
estate: {
is: null,
},
},
}); Maybe there is a better way that I don't know of. |
Another way to achieve the same would be: query {
listValuations(
where: {
estateUuid: { equals: null }
}
) {
id
}
} In theory this should work, though I've just tested it on my local machine - and it seems the event parser is transforming arguments: {
where: {
estateUuid: {
equals: undefined # this should be null
}
}
} Can you please try and let me know if you see the same issue on your end? |
I think it wouldn't hurt to bring back 12865a1#diff-0f3118d4d839ee46a643c4a03ad907f78569918a6a3cc248ab072e0e45bcba0aR52-R64 While making sure they do not get overriden, like how Prisma does it: export type ValuationWhereInput = {
AND?: Enumerable<ValuationWhereInput>
OR?: Enumerable<ValuationWhereInput>
NOT?: Enumerable<ValuationWhereInput>
...
estate?: XOR<EstateRelationFilter, EstateWhereInput> | null
}
export type EstateRelationFilter = {
is?: EstateWhereInput | null
isNot?: EstateWhereInput | null
} And just replacing the By the |
There is no proper way to express This is also why That said, not being able to use |
Do you think fixing that issue would then take care of my initial problem and let me filter on one-to-one relationship existence, where the foreign key is not available on the model that is being filtered? |
Yes, that's what I'm hopping for. |
See #94 |
@Tenrys you can install query {
listValuations (
where: {
estate: { is: NULL } # or `isNot: NULL`
}
) {
uuid
estate {
uuid
}
}
} Let me know if that solves your issue? |
Works perfect for relationships, however I tried Could make them use |
Should work better now if you install
|
A bug I found: if you try to use |
They seem to be missing in the currently generated GraphQL types, I'm not certain when they are and aren't available, but I think it would be nice to have the option to use them, maybe.
https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#is
I'm not sure if it would be as easy as modifying the schema generator template. For now I'll settle with
some
, I may take a look myself laterThe text was updated successfully, but these errors were encountered: