Bi-Directional data search

Sample Data:

{'title': 'Alpha', '_People': '*', 'age': 10}
{'title': 'Beta', '_People': '*', 'age': 20}

Relationship:

Alpha -(friend)> Beta

Query:

Fetch relationships of Alpha

query = """{
    all (func: has(_People))
        @filter(eq(title, Alpha)) {
            uid
            expand(_all_) {
                uid
                expand(_all_) {}
            }
    }
}"""

Properly gives: A → B

Fetch Relationships of Beta

query = """{
    all (func: has(_People))
        @filter(eq(title, Beta)) {
            uid
            expand(_all_) {
                uid
                expand(_all_) {}
            }
    }
}"""

Does not give B → A relationship


Hack that I already know, but its not efficient:

  • Create 2 relationships for everything, eg. A -> B and B -> A
1 Like

I didn’t quite understand the point. Can be specific and detailed?

Cheers

you need friend @reverse

then use ~friend, you can get B->A