In fact, going back to review my query against the context of the Dataset. It’s even worse than I thought if it were used in a real world dataset. Potentially in my query it would get absolutely ALL inhabitants of the united states. That would be catastrophic, as it would be over 300 million to find half a dozen. Totally at wrong-way.
This could be okay in small cases. Not like that one. The case with UID_IN can be used tho. I’ll show you how.
Nope, the uid_in val would take only the USA uid. The intention of UID_IN is just a single query level. Instead of writing one more nested block, you simply use one parameter of it one level earlier. And yeah, It could be a array of uids in other cases.
I have reviewed your query, indeed this approach is better.
{
me as var(func: eq(name, "Bob")) @cascade {
BobsFriends_In_EUA as friend {
locatedIn {
locatedIn @filter(eq(name, "United States"))
}
}
}
query(func: uid(me)) {
name
friend @filter(Not uid(BobsFriends_In_EUA)) {
name
locatedIn { name }
}
}
}
This would list all friends who are not in USA.
But we can go even futher, as cascade now is supported in subqueries.
{
query(func: eq(name, "Bob")) {
name
friendNot_In_US : friend @cascade {
name
locatedIn {
name
locatedIn @filter(NOT eq(name, "United States"))
}
}
}
}
Technically, this way we can apply filters at indefinite levels without using multiple blocks. The cascade in subquery is the key to write less.
Using uid_in can make it easier to “see” and understand for newbies in Graphql+-
. This same query I made earlier would look like this.
{
US as var(func: eq(name, "United States"))
query(func: eq(name, "Bob")) {
name
friendNot_In_US : friend @cascade {
name
locatedIn @filter(NOT uid_in(locatedIn, val(US))) {
name
}
}
}
}
Is basically the same thing. But vissually more “friendly”.
Without subquery cascade it would look like:
{
US as var(func: eq(name, "United States"))
Target as var(func: eq(name, "Bob")) {
friends as friend
}
#block filter
F as var(func: uid(friends))@cascade {
name
locatedIn { #OR => @filter(NOT uid_in(locatedIn, val(US)))
locatedIn @filter(NOT uid(US))
}
}
query(func: uid(Target)) {
name
friendNot_In_US : friend @filter( uid(F)) {
name
locatedIn {
from : name
}
}
}
}
As you can see, before subquery cascade life would be bad. Now with Sub cascade we can use just two blocks or one for a more “cascade” advanced users.