hasura / hasura/graphql-engine
Can't specify _eq AND _is_null: false
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
I'm trying to write:
```
_or: [
{
_and: [
{
fieldA: {_eq: $fieldA}
},
{
fieldB: {_eq: $fieldB}
}
]
},
{
_and: [
{
fieldC: {_eq: $fieldC}
},
{
fieldC: {_is_null: false}
}
]
}
],
```
When I run analyze on this though, I see:
`Filter: (((fieldA = ''::text) AND (fieldB = ''::text)) OR (fieldC IS NOT NULL))`
(I'm missing a "fieldC =" argument)
I want this to be the equivalent to the SQL:
```sql
(fieldA = $A and fieldB = $B) OR (fieldC = $C and fieldC is not null)
```
Basically, $C will sometimes be `null`. And with that:
* If $C is not null, then I want to include the 2nd term
* If $C is null, I'm effectively removing the second search term
I'm being told you basically can't do `{_eq: $C}` when $C is null.
This seems wrong to me-- if something is possible in SQL, it should be made possible in the graphql-engine wherever possible. It doesn't make sense to me that it be the client's responsibility to send 2 different queries (or write a custom postgres function) based on the arguments.
If at all possible, the capability to execute this type of query should be included.
Contributor guide
Research direction
No files, tests, or entry points are named. Start by reproducing the shown GraphQL filter with analyze and compare the generated filter with the requested SQL behavior; done means nullable _eq input can conditionally include the second search term without requiring separate client queries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, postgres
- Domain
- api, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100