graphile / graphile/pg-aggregates
Ordering in the aggregate column level is no longer possible in Postgraphile V5
- Dominant language
- TypeScript
- Stars
- 89
- Forks
- 19
- PR merge metrics
- No merged PRs in 30d
Description
### Summary
PgAggregatesPreset port missing ordering on aggregate fields. This was espacially useful when extending the aggregate functionality with further options like `array_agg`, where applied order will be applied to the results.
This was our plugin that heavily used it:
```
export const ARRAY_AGG_SMART_TAG = 'arrayAgg';
export const ArrayAggPlugin: Plugin = (builder) => {
builder.hook('build', (build) => {
const { pgSql: sql } = build;
const arrayAggSpec: AggregateSpec = {
id: 'arrayAgg',
humanLabel: 'array aggregation',
HumanLabel: 'Array aggregation',
isSuitableType: (pgType) => !!pgType.arrayType,
sqlAggregateWrap: (sqlFrag) => sql.fragment`coalesce(array_agg(${sqlFrag}), '{}')`,
pgTypeAndModifierModifier: (pgType) => [pgType.arrayType, null],
isNonNull: true
};
build.pgAggregateSpecs = [...build.pgAggregateSpecs, arrayAggSpec];
return build;
});
};
query:
{
projectsConnection {
groupedAggregates(groupBy: [TRADES]) {
keys
arrayAgg {
id (orderBy: [ID_ASC])
}
}
}
}
```
### Steps to reproduce
Try to set ordering in the aggregated field. For example:
```
{
projectsConnection {
groupedAggregates(groupBy: [TRADES]) {
keys
sum {
id (orderBy: [ID_ASC])
}
}
}
}
```
### Expected results
It will apply the sorting to the aggregated result. Graphql schema will support ordering on aggregate field.
### Actual results
Doesn't support.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.