hasura/graphql-engine · error · Error

Cannot perform an order by target of type ${orderByElement.t

Error message

Cannot perform an order by target of type ${orderByElement.target.type} on the current table. Only column-typed targets are supported.

What it means

When an order-by element's target_path is empty (sort on the current table), the target must be a plain column; redaction expressions and value coercion only apply to column targets. Any other target type (aggregates, etc.) on the current row is rejected with this error.

Source

Thrown at dc-agents/reference/src/query.ts:504

    );
  }
};

const makeGetOrderByElementValue =
  (
    findRelationship: (relationshipName: RelationshipName) => Relationship,
    applyRedaction: ApplyRedaction,
    performQuery: (targetName: TargetName, query: Query) => QueryResponse,
  ) =>
  (
    orderByElement: OrderByElement,
    row: Record<string, RawScalarValue>,
    orderByRelations: Record<RelationshipName, OrderByRelation>,
  ): RawScalarValue => {
    const [relationshipName, ...remainingPath] = orderByElement.target_path;
    if (relationshipName === undefined) {
      if (orderByElement.target.type !== 'column')
        throw new Error(
          `Cannot perform an order by target of type ${orderByElement.target.type} on the current table. Only column-typed targets are supported.`,
        );
      return applyRedaction(
        row,
        orderByElement.target.redaction_expression,
        coerceUndefinedToNull(
          row[getColumnSelector(orderByElement.target.column)],
        ),
      );
    } else {
      const relationship = findRelationship(relationshipName);
      const orderByRelation = orderByRelations[relationshipName];
      const innerOrderByElement = {
        ...orderByElement,
        target_path: remainingPath,
      };
      const query = {
        ...buildQueryForPathedOrderByElement(

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Give aggregate order-by targets a relationship path (non-empty target_path) so they are computed via subquery, per the engine's design.
  2. For sorting by the row's own column, use target.type 'column' with target_path: [columnName].
  3. Validate order_by elements before dispatch: empty path implies type 'column'.

Example fix

// before
{ target_path: [], target: { type: 'single_column_aggregate', column: 'name', function: 'max', ... }, order: 'asc' }

// after
{ target_path: ['tracks', 'name'], target: { type: 'single_column_aggregate', column: 'name', function: 'max', ... }, order: 'asc' }
Defensive patterns

Strategy: validation

Validate before calling

if (orderBy.target_path.length === 0 && orderBy.target.type !== 'column')
  throw new Error('empty order_by path requires a column target');

Type guard

const isColumnTarget = (t: { type: string }): t is { type: 'column'; column: string } => t.type === 'column';

Prevention

When it happens

Trigger: An order_by element with an empty target_path and target.type other than 'column' — e.g. target: { type: 'single_column_aggregate', ... } with target_path: [].

Common situations: Hand-constructed or programmatically generated QueryRequests that pair aggregate targets with empty paths; connector backends emitting order_by elements incorrectly.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/a734f0fa8c93169c. Report an issue: GitHub.