Something like this should work for you.
{
me as var(func: uid(0x1)) {
sc as math(1) # Give a score of 1 to the user
fr as friend {
friend {
fscore as math(sc) # This will be number of common friends
}
}
}
# Get top ten people with highest score
TopRecommendations(func: uid(fscore), orderdesc: val(fscore), first: 10) @filter(not uid(fr,me)) { # Remove the user and his friends
name
# Fetch the friends of recommendations and intersect with the friends of uid(0x1) to get list of mutual friends.
friend @filter(uid(fr)) {
uid
name
}
}
}
Also, there was a some problem in your data-set which I have rectified and shared the updated data-set below.
{
"set": [
{
"name": "A",
"uid": "0x1",
"friend": [
{
"name": "B",
"uid": "0x2"
},
{
"name": "C",
"uid": "0x3"
},
{
"name": "E",
"uid": "0x5"
}
]
},
{
"name": "B",
"uid": "0x2",
"friend": [
{
"name": "D",
"uid": "0x4"
}
]
},
{
"name": "C",
"uid": "0x3",
"friend": [
{
"name": "D",
"uid": "0x4"
}
]
},
{
"name": "D",
"uid": "0x4",
"friend": [
{
"name": "B",
"uid": "0x2"
},
{
"name": "C",
"uid": "0x3"
}
]
},
{
"name": "E",
"uid": "0x5",
"friend": [
{
"name": "A",
"uid": "0x1"
},
{
"name": "F",
"uid": "0x6"
}
]
},
{
"name": "F",
"uid": "0x6",
"friend": [
{
"name": "E",
"uid": "0x5"
}
]
}
]
}
Note - How node D was connected to itself i.e. to a node with name C but uid as 0x4 which caused inconsistencies in the query result.