Howto filter by propagating a variable

This happens cuz each piece of the query is kind of independent. For me, it turns out to be a bug. Also, I have an internal discussion about this.

As you can see at Get started with Dgraph. During a query, Dgraph searches for each pred/edge. It would be at different groups and so on. So technically each pred is a “call”. And they are independent per se. So, when you use it in the same query block. It accuses that it is missing an argument. Cuz that predicate was empty (the query for it has not yet been made or for some reason, and the value has not been saved to be used in the nested block - AND the nested block won’t wait for the parent to finish).

A workaround for this issue is by doing two blocks. e.g.

{
   K as var(func: type("Person")) @filter(eq(name, "Me")) {
       rated {
        rate1 as rate
       }
   }
  b(func: uid(K) ) @ignorereflex @cascade {
    name
    rated {
      movie {
        name
        with_ratings: ~movie @filter(eq(rate, val(rate1))) {
          rate
          people: ~rated {
            name
          }
        }
      }
    }
  }
}
1 Like