Filter by counts in GraphQL

Looking at the Dgraph tour, I can

Find all people who are in their 20s, and have at least 2 friends.

  lots_of_friends(func: ge(count(friend), 2)) @filter(ge(age, 20) AND lt(age, 30)) {
    friend {

How would you do this in GraphQL? A custom query backed by a lambda? If so then you lose all of the power of selecting fields and filtering on the subgraph.

Hi @verneleem, we have aggregate functions in GraphQL but can’t use them in the filter as of now.
you can use the above DQL query in GraphQL using the custom DQL feature and for that you need to define schema appropriately.
Let me know if you need any help.

1 Like