Avoid initial node in reverse traversal

Hi,

I have a schema where EntityA links to EntityB, with a reverse edge. I need to traverse from a single EntityA, to EntityB, and then back to all EntityA’s exluding the original EntityA node. I always seem to get the original EntityA in my second hop no matter what i try. Does anyone know how to do this?

Thanks!
Rob

Try these approaches

{
  var(func: eq(name, "EntityA")) {
    getB as edgeToEntityB
  }
  q(func: uid(getB)) {
    name
    ~edgeToEntityB {
      name
    }
  }
}

OR

{
  var(func: eq(name, "EntityA")) {
    edgeToEntityB {
      getB as ~edgeToEntityB
    }
  }
  q(func: uid(getB)) {
    name
  }
}

Sorry, reading back my question wasnt clear @MichelDiz. By EntityA i mean a node “type”. So Entity 1 (Type A) links to Entity 2 (Type B) via link ~HasB. From Entity 2, I want to then traverse back via HasB to all other Type A entities (e.g. Entity 2,3,4) without getting Entity 1 a second time in this traversal. Is this possible?

Try this

{
  var(func: type("A")) {
    A as uid
    edgeToEntityB {
      getB as ~edgeToEntityB
    }
  }
  q(func: uid(getB)) @recurse {
    name
    HasB @filter(NOT uid(A))
  }
}

If it doesn’t work, please provide samples and examples. But it should work for what I got from the issue.

1 Like