graph-node
graph-node copied to clipboard
Expose AND and OR logical operators in GraphQL query filters
Where filters should allow AND and OR logical operators to combine and nest conditions in the GraphQL queries.
The way this was initially intended to look like was:
{
users(where:
# implicit AND at the top level
{
name_startsWith: "A",
OR: {
name_endsWith: "c",
name_endsWith: "d",
AND: {
name_contains: "o",
name_contains: "i",
}
}
}
) {
...
}
}
The above would return all users whose names start with "A" and either
- ends with "c"
- ends with "d"
- contains an "o" and an "i"
Open questions:
- Is this a good design? (How do others do it?)
- Do we want to enforce a limit on the depth? (1-2-3 levels?)
I'd also like this, especially because I cannot match null using *_in:
query {
erc721Tokens(
orderBy: identifier,
orderDirection: asc,
where: {hat_in:["Bucket", "Cowboy"]}
) {
identifier
owner {
id
}
}
}
What I really need is matching where Bucket || Cowboy || null.
I think this would be intuitive, especially since both hat_in:["Bucket", "Cowboy"] and hat:null work as expected when ran individually:
query {
erc721Tokens(
orderBy: identifier,
orderDirection: asc,
where: {hat_in:["Bucket", "Cowboy"] OR hat:null}
) {
identifier
owner {
id
}
}
}
Is this supposed to only work on the same field or can we combine multiple fields like:
where: {hat_in: ["bucket", "Cowboy"] OR shoe: "46"}
https://github.com/graphprotocol/graph-node/pull/4080