How to aggregate with @cascade filter?

I want to implement pagination. My query uses @cascade for nested filtering since nested object filters are not supported. How can I know the total result count for pagination?

Assuming we have the following schema:

type Person {
    name: String @search(by:[hash])
}

type Pet {
    name: String
    owner: Person
}

type School {
    hasPet: [Pet]
}

I now want to aggregate all the pets in school who has an owner named john:

query {
  querySchool @cascade {
    # get all pets with owner john
    hasPet {
      name
      owner (filter: {name: {eq: "john"}}){
        name
      }
    }
    
    # I want to count all pets with owner john
    hasPetAggregate (filter: {...}){
      count
    }
  }
}

Obviously, the @cascade directive does not affect the hasPetAggregate. So, how can I achieve this without querying for all Pets that match my filter especially when my database is large?

1 Like

You need Custom DQL for that at this point.

J

1 Like