Skip to content

Aggregation Queries

Igor Dianov edited this page May 29, 2024 · 2 revisions

You can fetch aggregations on entity fields/relationship groups using an aggregation query.

The name of the aggregate field is of the form aggregate as part of the select queryr

The currently supported aggregation functions are count. Aggregation support for other functions sum, avg, max, min, etc. will be added soon.

Fetch aggregated data of an object

{
  Books {
    aggregate {
      count
    }
  }
}
{
  "data": {
    "Books": {
      "aggregate": {
        "count": 5
      }
    }
  }
}

Fetch aggregated data on nested objects

{
  Books {
    aggregate {
      count
      by {
        author {
          by(field: name)
          count
        }
      }
    }
  }
}
{
  "data": {
    "Books": {
      "aggregate": {
        "count": 5,
        "by": {
          "author": [
            {
              "by": "Anton Chekhov",
              "count": 3
            },
            {
              "by": "Leo Tolstoy",
              "count": 2
            }
          ]
        }
      }
    }
  }
}
Clone this wiki locally