@reverse dircetive

Sorry for the delay.

If the direction doesn’t add new information about the relation. I would use a reverse index. Otherwise, I would create two edges that represent a concept. e.g: “if a user has an outgoing edge called <askfriendship> and an incoming edge <acceptedfriendship> - so this user has a friend”.

I personally use reverse edges just to traverse. Applying complex filtering.

Well, if you have a deep relation, traversing with the reverse directive is your tool.

That’s a normal traversing through the nested graph.

Normal direction

{
  var(func: eq(User.username, "Lucas")){
    User.memberships {
     REPOS as Membership.in_repository
    }
  } 
  q(func: uid(REPOS)){
    Name : Repository.name
  }
}

Reverse direction

{
  var(func: eq(Repository.name, "Something")){
    <~Membership.in_repository> {
     User as <~User.memberships>
    }
  } 
  q(func: uid(User)){
    Name : User.username
  }
}

Both <Membership.in_repository> and <User.memberships> have to have the reverse directive in the schema.

2 Likes