Tyler_D
(Tyler D)
October 5, 2021, 2:22am
1
Lets say you have a schema like so.
type school {
students: [student]
}
type student {
name: String
}
How would you be able to query schools that have X number of students or schools that are empty of students?
Something like
query {
queryschool(filter: { students: {lt: 2}) {
students
}
}
or
query {
queryschool(filter: { students: {eq: 0}) {
students
}
}
thanks!
amaster507
(Anthony Master)
October 5, 2021, 2:44am
2
AFAIK, you still can’t query by count, but you can query by existence and non-existence using the has
filter.
Tyler_D
(Tyler D)
October 5, 2021, 2:47am
3
I see thanks for the answer here, are you able to do a “reverse” has to query empty schools for example?
amaster507
(Anthony Master)
October 5, 2021, 2:53am
4
Well, this is tagged GraphQL, so as far as GraphQL “reverse” actually uses hasInverse directive that creates an edge from both directions it is definitely possible. I’m not sure 100% if DQL @reverse allows you to use has on a reverse edge though, i would have to trial-and-error that one to know for sure.
Tyler_D
(Tyler D)
October 5, 2021, 2:55am
5
Thanks for your help on this. Seems like I can at least get empty schools with something like
query {
queryschool(filter: {not: {has: students} }) {
students
}
}