Writing a query to get all common descendants

I’m trying to write a query that gets me all common descendants of uids in a query variable

I only got as far as

# TODO match each ANCESTOR_QUERIED_BLOCKS uid, not any

  e(func: uid(ANCESTOR_QUERIED_BLOCKS)) @recurse(depth: 1000) {
      DESCENDANTS as uid
      name
      relation
  }

which returns all descendants of all ANCESTOR_QUERIED_BLOCKS, but I want the ones that are a descendant of every uid in ANCESTOR_QUERIED_BLOCKS.

Is this possible?

Hi @Emil,

I don’t think that there is a direct way to achieve this. What I can suggest you, is to fetch the descendants for each UID and then process the result in the client side to find the ones that are descendant of every uid in ANCESTOR_QUERIED_BLOCKS.

Tagging @MichelDiz, if he has some direct approach.

How many blocks of ANCESTOR_QUERIED_BLOCKS are there? If they are not too many, you could something like this:

  e(func: uid(Block_1)) @recurse(depth: 1000) {
      DESCENDANTS as uid
      name
      relation
  }
 f(func: uid(Block_2)) @recurse(depth: 1000) @filter(uid_in(relation, uid(DESCENDANTS))){
      DESCENDANTS2 as uid
      name
      relation
  }

Could be any amount. It’s a variable I get from another part of the query.

Thanks! Will consider this, as well as doing 2 queries (query 1 as op, query 2 built something like @Anurag’s answer on the client), and do some perf testing on that

1 Like