2

I have a GraphQL+- query in which I want to get mutual friends of two people. But I really couldn't find any option to use some sort of intersection of two graphs... can someone help me? Here is my code:

{
  catarinas_friends(func: eq(name, "Catarina"))
  {
    friend 
    {
      name
    }
  }

  michaels_friends(func: eq(name, "Michael")) {
    friend
    {
      name
    }
  }
# I want to intersect those two
}
MacakM
  • 1,804
  • 3
  • 23
  • 46

1 Answers1

0

This works for you?

{
  var(func: eq(name@., "Michael")) {
    MF as friend
  }

  var(func: eq(name@., "Amit")) {
    CF as  friend
  }

  in_common(func: uid(MF)) @filter(uid(CF)){
    name@.
  }

}

with this dataset https://tour.dgraph.io/master/intro/4/ You can have the common friends.

You can also use K-Shortest Path Queries

The middle one in the response is the closest common entity.