UsageAggregation

Aggregation

BaseQL’s aggregation feature provides powerful counting capabilities across your data, enabling you to build analytics dashboards, implement pagination, and gather insights without loading full record data.

Getting Access

This feature is currently in preview - contact [email protected] to request early access.

Supported Data Sources

Supported by:  

Root Aggregations

Access _aggregates at the query root to count records across entire tables:


{
_aggregates {
people {
count
}
cities {
count
}
}
}

This returns the total count of records in each specified table, perfect for dashboard metrics and overview statistics.

Relation Aggregations

Access _aggregates on individual records to count related records:


{
people(name: "ben") {
name
_aggregates {
friends {
count
}
}
}
}

This allows you to count related records for each parent record, enabling rich data insights and relationship analysis.

Filtering Support

Both aggregation types support the same powerful filtering options as regular queries.

Direct Field Arguments

Filter aggregations using direct field arguments:


{
_aggregates {
people(vegan: true) {
count
}
}
}

Complex Filters with _filter

Use the advanced filtering DSL for complex conditions:


{
_aggregates {
people(_filter: {
_and: [
{ vegan: { _eq: true } },
{ netWorth: { _gte: 5000 } }
]
}) {
count
}
}
}

Relation Filtering

Apply filters to relation-level aggregations:

{
people {
name
_aggregates {
friends(_filter: { vegan: { _eq: true } }) {
count
}
}
}
}

Use Cases

Pagination

Get total counts for implementing pagination UI:

{
_aggregates {
people {
count
}
}
people(_page_size: 3, _page: 1) {
name
}
}

Analytics Dashboard

Display summary statistics across multiple tables:


{
_aggregates {
allPeople: people {
count
}
veganPeople: people(vegan: true) {
count
}
cities {
count
}
}
}

Multiple Aggregations

Combine multiple aggregations in a single query using aliases:


{
_aggregates {
allPeople: people {
count
}
veganPeople: people(vegan: true) {
count
}
wealthyVegans: people(_filter: {
_and: [
{ vegan: { _eq: true } },
{ netWorth: { _gte: 10000 } }
]
}) {
count
}
}
}

Need Help? If you have questions about aggregations or need assistance with your specific use case, reach out to [email protected].