How to get source uids without a reverse query?

(护群神兽之点赞狂魔) #1
  Alice  <friend>  Tom 
  Alice  <friend>  Bob
  Bob   <friend>  Tom 

If I 'm Tom. I want to know who point to me with a edge friend.
I should get the answer “Alice, Bob”.
I can do it with “~friend”.

query x{
   x(func: uid(Bob'sUid)){

However, I want to know, Is there any other way to make it ,without <~friend>?

(Michel Conrado) #2

The best way is using the reverse notation ~ tilde. But you could do it by adding more blocks to your query. That mean you’d have to search for all users (so it will use a lot of resources of the cluster) and then check who is friend of bob as “parent” to “child” direction. So, It is more easy stick with the tilde right? but you can do it.


query x{
   x(func: has(is_user)) @filter(uid_in(friend, Bob'sUid){

PS. could be also “has(friend)” no problem.

(护群神兽之点赞狂魔) #3

thank you , uid_in looks good .

(system) closed #4

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.