More case with above dataset:
Find friends that have studied at the same school as mine.
{
q(func: type(Person), first:1) @cascade{
uid
name
jobTitle
studied_at {
uid
name
}
friend {
name
studied_at @filter(eq(name, "Main City School")) {
uid
name
}
}
}
}
Result (This is a desired result)
{
"data": {
"q": [
{
"uid": "0x1",
"name": "Jane Doe",
"jobTitle": "Student",
"studied_at": [
{
"uid": "0x6",
"name": "Main City School"
}
],
"friend": [
{
"name": "Lucas Doe",
"studied_at": [
{
"uid": "0x6",
"name": "Main City School"
}
]
},
{
"name": "Olivia Doe",
"studied_at": [
{
"uid": "0x6",
"name": "Main City School"
}
]
}
]
}
]
}
}
But, we need a clean query tho
{
q(func: type(Person), first:1) @cascade{
uid
name
jobTitle
studied_at {
uid
STAT as name
}
friend {
name
studied_at @filter(eq(name, val(STAT))){
uid
name
}
}
}
}
This query above isn’t possible to run. Cuz We do not pass the variable value to the next nested block. So that’s why we need to “promise” it.
But, we need an even cleaner query tho!
This one would be perfect.
{
q(func: type(Person)){
uid
name
jobTitle
studied_at {
STAT as uid
name
}
friend @filter(uid_in(studied_at, val(STAT))){
name
}
}
}