Aggregate queries

Aggregate queries in GraphQL are useful for summarizing data in various ways. They help in performing operations such as counting the number of records, summing up numerical fields, and grouping data based on specific fields.

Add _aggregate with any asset type to perform aggregate queries. _count, _sum and _groupby are currently supported.

Count Query

The count query allows you to count the number of records that match a specific condition.

{
    Invoice_aggregate {
        _count
    }
}

Example:

{
    Invoice_aggregate (status: "updated") {
        _count
    }
}

In this example, the query counts the invoices a 'updated' status.


Sum Query

The sum query allows you to sum the values of a specific numerical field across all records that match a given condition.

{
    Invoice_aggregate {
        _sum {
            amount
        }
    }
}

Example:

query {
  Invoice_aggregate(where: { status: "updated" }) {
          _sum {
              amount
        }
      }
}

In this example, the query sums up the amount of all invoices that have a 'updated' status.


Group By Query

The groupBy query allows you to group records by a specific field and perform aggregate functions like count or sum within each group.

{
    Invoice_aggregate {
        _count
        _groupby{
            invoiceType
        }
    }
}

Example:

{
    Invoice_aggregate (status: "updated") {
        _count
        _groupby{
            invoiceType
        }
    }
}

This query groups invoices by their type and provides the count of the invoices with 'updated' status.

Last updated