Friend recommendation get Common friends

Dgraph data like this

{
        "mid": 6659373913526501000,
        "uid": "0x1",
        "friends": [
          {
            "mid": 6659373935517238000,
            "uid": "0x2"
          },
          {
            "mid": 6659373952495781000,
            "uid": "0x3"
          }
        ]
}

It very useful to recommend friend by the query:

{
 me as var(func: uid(<userid>)) {
  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(me, fr)) { # Remove the user and his friends 
  name
 }
}

We can use this query to find the users that need to be recommended
Further, Can we find the common friends with the recommended in this query?

A <friend> B<friend> D
A <friend> C<friend> D

D will be recommended to A,how can I get the B、C information use this query?

create edge mutate:

{
    "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": "0x4"
                }
            ]
        },
        {
            "name": "E",
            "uid": "0x5",
            "friend": [
                {
                    "name": "A",
                    "uid": "0x1"
                },
                {
                    "name": "F",
                    "uid": "0x6"
                }
            ]
        },
        {
            "name": "F",
            "uid": "0x6",
            "friend": [
                {
                    "name": "E",
                    "uid": "0x5"
                }
            ]
        }
    ]
}

As I understand it from your query, you are collecting second-level friends. In other words, the friends of “A” friends. That way, the more friends of friends have repeated. More “points” you give him. And it rises in the ranking. Right? It seems to me that this is the criterion.

I didn’t quite understood this question.

In fact, C and F will be recommended for A. In your last dataset sample.

{
  "data": {
    "TopRecommendations": [
      {
        "name": "C",
        "fscore": 2
      },
      {
        "name": "F",
        "fscore": 1
      }
    ]
...

In your query B is never reached. B is linked to C and C to B and C again.

Thanks for your reply

ps: D and F will be recommenced for A

In fact, I want to find a way not only get the D、F information but also the mutual friends between
A and D
the result may be like this:

{
    "data": {
        "TopRecommendations": [
            {
                "name": "D",
                "fscore": 2,
                "common": [
                    {
                        "name": "B",
                        "uid": "0x2"
                    },
                    {
                        "name": "C",
                        "uid": "0x3"
                    }
                ]
            },
            {
                "name": "F",
                "fscore": 1,
                "common": [
                    {
                        "name": "E",
                        "uid": "0x5"
                    }
                ]
            }
        ]
    }
}

this work for me

{
 me as var(func: uid(<userid>)) {
  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(me, fr)) { # 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
  }
 }
 }
}