Skip to content

Ordering in the aggregate column level is no longer possible in Postgraphile V5Β #88

@erbold-bu

Description

@erbold-bu

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions