Another “Promise” usage.
The dataset in the end.
Consider this query.
I want to return friends from a particular user and filter these friends’ students at the same school as the user.
This first query does it, but you need to know the UID from the school in hand
{
q(func: uid(0x4e36)){
uid
name
jobTitle
studied_at { name }
friend @filter(uid_in(studied_at, "0x4e3b")){
name
}
}
}
To make it work, we need to solve this “Add support of Value Variables for uid_in. #3066” and support pass a value variable to a nested block. Which is the main point of this topic “Promise a nested block”.
if we fix only the 3066 the query would be like
{
var(func: uid(0x4e36)){
STAT as studied_at
}
q(func: uid(0x4e36)){
uid
name
jobTitle
studied_at { name }
friend @filter(uid_in(studied_at, val(STAT))){
name
}
}
}
But if we fix 3066 and also add support to pass a value variable to a nested block the query would be like - And that one would be just perfect
{
q(func: uid(0x4e36)){
uid
name
jobTitle
STAT as studied_at
friend @filter(uid_in(studied_at, val(STAT))){
name
}
}
}
#And of course this would be nice to wide queries like
I want to return friends from all users and filter these friends’ students at the same school as the user.
{
q(func: type(Person)){
uid
name
jobTitle
STAT as studied_at
friend @filter(uid_in(studied_at, val(STAT))){
name
}
}
}
Dataset for this
{
"set": [{
"uid": "_:School1",
"dgraph.type": "School",
"name": "Main City School",
"telephone": "(425) 123-4567",
"url": "http://www.maincityschool.com"
},
{
"uid": "_:School2",
"dgraph.type": "School",
"name": "Other City School",
"telephone": "(425) 333-4567",
"url": "http://www.othercityschool.com"
},
{
"uid": "_:Jane",
"dgraph.type": "Person",
"name": "Jane Doe",
"jobTitle": "Student",
"studied_at": [{
"uid": "_:School1"
}],
"friend": [{
"uid": "_:Lucas"
},
{
"uid": "_:Noah"
},
{
"uid": "_:Olivia"
},
{
"uid": "_:Sophia"
}
]
},
{
"uid": "_:Lucas",
"dgraph.type": "Person",
"name": "Lucas Doe",
"jobTitle": "Student",
"studied_at": [{
"uid": "_:School1"
}],
"friend": [{
"uid": "_:Jane"
},
{
"uid": "_:Olivia"
},
{
"uid": "_:Noah"
},
{
"uid": "_:Sophia"
}
]
},
{
"uid": "_:Olivia",
"dgraph.type": "Person",
"name": "Olivia Doe",
"jobTitle": "Student",
"studied_at": [{
"uid": "_:School1"
}],
"friend": [{
"uid": "_:Jane"
},
{
"uid": "_:Lucas"
},
{
"uid": "_:Noah"
},
{
"uid": "_:Sophia"
}
]
},
{
"uid": "_:Noah",
"dgraph.type": "Person",
"name": "Noah Doe",
"jobTitle": "Student",
"studied_at": [{
"uid": "_:School2"
}],
"friend": [{
"uid": "_:Jane"
},
{
"uid": "_:Lucas"
},
{
"uid": "_:Olivia"
},
{
"uid": "_:Sophia"
}
]
},
{
"uid": "_:Sophia",
"dgraph.type": "Person",
"name": "Sophia Doe",
"jobTitle": "Student",
"studied_at": [{
"uid": "_:School2"
}],
"friend": [{
"uid": "_:Jane"
},
{
"uid": "_:Lucas"
},
{
"uid": "_:Olivia"
},
{
"uid": "_:Noah"
}
]
}
]
}