GraphQL Conditional Queries
This is possible-it would have to be different. Your query wouldn't be a valid GQL query. Something like this would:
{
users(where: {age: { $gt: 18 }}){ #inspired by mongoDB query api
name
age
}
}
or maybe simpler:
{
users(where: {age: ">18"}}){
name
age
}
}
of course either way the resolver on the backend needs to expect this where
argument on the users
field and construct the DB query accordingly when it is passed. You would not find this in GraphQL docs because GraphQL itself doesn't care about that. It only showcases how to use features of GraphQL.
If you tried example projects like for example star was api, those don't have any filtering built in.
You should send your age filter as a parameter.You might try the following one:
In your graphql file
type users {
name: String,
age: Int,
...
}
usersQuery(ageLimit: Int): [users]
also you can send '>' , '<' , '=' as a parameter. Also it seems like that
usersQuery(ageLimit: Int, ageOperator: String): [users]
and you should configure your resolver where statement with these operators. hope it helps you.