GraphQLAggregationBuilder class

Fluent builder for a Data API Builder (DAB) groupBy aggregation query.

Instances are returned from GraphQLQueryBuilder.groupBy or GraphQLQueryBuilder.aggregate. The generated GraphQL contains only a groupBy selection and never emits items, endCursor, or hasNextPage, because DAB rejects a query that combines groupBy with items.

Example

const rows = await client.data.Order
  .where({ status: { eq: 'shipped' } })
  .groupBy(['region'])
  .aggregate({
    revenue: { sum: 'amount' },
    orders:  { count: 'quantity' },
  })
  .execute();

Constructors

GraphQLAggregationBuilder<TSchema, TEntity, TGroup, TSpec>(GraphQLClient, string, string, TGroup, TSpec)

Creates an aggregation builder. Prefer chaining from a GraphQLQueryBuilder instead of calling this directly.

Methods

execute()

Execute the aggregation query and return one row per group.

Constructor Details

GraphQLAggregationBuilder<TSchema, TEntity, TGroup, TSpec>(GraphQLClient, string, string, TGroup, TSpec)

Creates an aggregation builder. Prefer chaining from a GraphQLQueryBuilder instead of calling this directly.

new GraphQLAggregationBuilder(graphqlClient: GraphQLClient, entityPluralName: string, filterFragment: string, groupBy: TGroup, spec: TSpec)

Parameters

graphqlClient
GraphQLClient

The underlying GraphQL client.

entityPluralName

string

The DAB query root (lowercased pluralized entity).

filterFragment

string

The pre-built filter: { ... } GraphQL fragment (or an empty string when no where was supplied). Passed in so this builder does not re-implement filter serialization.

groupBy

TGroup

The scalar fields to group by.

spec

TSpec

The alias-keyed aggregation specification.

Method Details

execute()

Execute the aggregation query and return one row per group.

function execute(): Promise<GroupedAggregationRow<TSchema[TEntity], TGroup, TSpec>[]>

Returns

Promise<GroupedAggregationRow<TSchema[TEntity], TGroup, TSpec>[]>

An array of { fields, aggregations } entries. When no grouping fields are supplied the array contains a single grand-total entry with an empty fields object.