The query for this would be like
{
var(func: eq(name, "United States")) {
~locatedIn { isHere as ~locatedIn { name } }
}
query(func: eq(name, "Bob")) {
friendNot_In_US : friend @filter(NOT uid(isHere)) {
name
locatedIn { name }
}
}
}
The response
{
"data": {
"query": [
{
"friendNot_In_US": [
{
"name": [
"Lilian"
],
"locatedIn": [
{
"name": [
"Quebec"
]
}
]
}
]
}
]
}
}
But there’s a problem here. If you query like this. You gonna receive internally all Persons who live in the US, it could be millions - for small context is okay tho. In general, this isn’t performative. In this case, UID_IN would be very handy. But we need support Add support of Value Variables for uid_in. · Issue #3066 · dgraph-io/dgraph · GitHub for variables.
The sample created to test this
{
"set":[
{
"uid":"_:Bob",
"dgraph.type":"Person",
"name":"Bob",
"telephone":"(425) 123-4567",
"friend":[
{
"uid":"_:Julian"
},
{
"uid":"_:Lilian"
}
],
"locatedIn":[
{
"uid":"_:SF"
}
]
},
{
"uid":"_:Julian",
"dgraph.type":"Person",
"name":"Julian",
"telephone":"(425) 322-0551",
"friend":[
{
"uid":"_:Bob"
},
{
"uid":"_:Lilian"
}
],
"locatedIn":[
{
"uid":"_:SF"
}
]
},
{
"uid":"_:Lilian",
"dgraph.type":"Person",
"name":"Lilian",
"telephone":"(425) 322-0551",
"friend":[
{
"uid":"_:Bob"
},
{
"uid":"_:Julian"
}
],
"locatedIn":[
{
"uid":"_:Quebec"
}
]
},
{
"uid":"_:US",
"dgraph.type":"Country",
"name":"United States"
},
{
"uid":"_:CAD",
"dgraph.type":"Country",
"name":"Canada"
},
{
"uid":"_:Quebec",
"dgraph.type":"City",
"name":"Quebec",
"locatedIn":[
{
"uid":"_:CAD"
}
]
},
{
"uid":"_:SF",
"dgraph.type":"City",
"name":"San Francisco",
"locatedIn":[
{
"uid":"_:US"
}
]
}
]
}