I have a query like this:
query getUsers ($setId: Int) {
user(where: { user_sets: { set_id: { _in: [$setId] } } }) {
id
name
status
user_sets {
set {
name
}
}
# more fields...
}
}
What I'm looking for, is a way to not apply the where
filter and give all entries if $setId
is null. I'd like to avoid dynamically writing the query - it'd be easy to do something like this, but we want queries in static .graphql files:
const query = `
query getUsers (${ setId ? '$setId: Int' : ''}) {
user(${ setId ? 'where: { user_sets: { set_id: { _in: [$setId] } } }' : '' }) {
`
Some things I've tried:
- Using GraphQL directives like
@skip
and@include
, but it seems these only apply to fields returned, not to any part of awhere
filter - Using Hasura
boolExp
s like_is_null
and_or
, but it seems these can't test variables directly, they can only compare variables to columns contents