Combine results from query blocks

I’m trying to create a query to get a paged, sorted, and access checked list of things in one database operation. I’m having trouble with combining uids from multiple previous query blocks into a single list of uids. Is this possible?

What I’m trying to do roughly resembles the query below.

query GetAccessCheckedUids(some vars...) {
  query1GetsFilteredUids (condition) some filters ... {
    filteredUids as uid
  }

  query2ChecksAccess(func: uid(filteredUids)) {
    access1 as uid
  }
  
  query3ChecksAccess(func: uid(filteredUids)) {
    access2 as uid
  }

  query4GetsPagedList(func: uid(access1 and access2), ...pageInfo) {
    fields...
  }

  query5CountsResults(func: uid(access1 and access2) {
    count(uid)
  }
}

I named the first three blocks for clarity (I hope). In the final query they will be var blocks.

I suppose all the nodes will be of the same type, so I can use (func: type(myType) @filter(uid(access1) or uid(access2))). I’m interested to know if there’s a better way to handle this though.

You can use func: uid(access1,access2) to sum variable nodes or (func: uid(access1)) @filter(uid(access2)) if you need both true

2 Likes