DQL: Am I using vars correctly?

Given this (elided) SDL schema:

interface Person {
    id: ID!
    email: String! @id
}

type Worker implements Person {
    abilities: [Ability] @hasInverse(field:worker)
}

type Ability {
    id: ID!
    worker: Worker!
    knowledge: Knowledge
}

interface Knowledge {
    id: ID!
}

This query correctly returns only Persons with the specified Knowledge:

{
 q(func: has(Worker.abilities))@cascade {
    uid
    Worker.abilities @filter(uid_in(Ability.knowledge, 0x2e0))
  }
}

However, when assigning (the uids of) that query to a var, all Workers are returned, not those restricted by the filter.

{
  var(func: has(Worker.abilities))@cascade {
    A AS uid
    Worker.abilities @filter(uid_in(Ability.knowledge, 0x2e0))
  }
      
  results(func: uid(A)) {
    uid
  }    
}

Any help appreciated.

1 Like

Looks like you have found a logical bug in the query process. But the “right” way of doing it is.

{
  A as var(func: has(Worker.abilities))@cascade {
    Worker.abilities @filter(uid_in(Ability.knowledge, 0x2e0))
  }
      
  results(func: uid(A)) {
    uid
  }    
}

OK, FYI this “right” way of doing it is actually returning the correct results! Thanks.

In case others are watching/searching (maybe searching for pagination strategies with DQL), I’m combining the above with another query block to retrieve a total count of the filter using count(uid).