Continuing foreach in Queries
Inspired by Shortest path syntax Get started with Dgraph I thought of a new way with foreach in mind, for query in Suggestions to Improve GroupBy example
In this case foreach would be a reserved word.
{
var(func: has(group_name)) {
member @groupby(first_name) {
Group as count(uid)
}
}
# It gets the name of the "block"
# from "first_name" predicate
foreach(func: uid(Group)) {
first_name
last_name
Total_with_this_name : val(Group)
}
}
The result
{
"data": {
"q": [
{
"Michel": [
{
"Total_with_this_name": 6
},
{
"uid": "0x1",
"first_name": "Michel"
},
{
"uid": "0x6",
"first_name": "Michel"
},
{
"uid": "0x8",
"first_name": "Michel"
},
{
"uid": "0x9",
"first_name": "Michel"
},
{
"uid": "0xf",
"first_name": "Michel"
},
{
"uid": "0xa",
"first_name": "Michel"
}
]
},
{
"Daniel": [
{
"Total_with_this_name": 3
},
{
"uid": "0x2",
"first_name": "Daniel"
},
{
"uid": "0xf22",
"first_name": "Daniel"
},
{
"uid": "0xf4",
"first_name": "Daniel"
}
]
},
{
"Lucas": [
{
"Total_with_this_name": 3
},
{
"uid": "0x3",
"first_name": "Lucas"
},
{
"uid": "0xf44",
"first_name": "Lucas"
},
{
"uid": "0xf77",
"first_name": "Lucas"
}
]
}
]
}