hasura/graphql-engine · error · OrderByExpressionIssue

The orderable field "{field_name}" has field arguments and c

Error message

The orderable field "{field_name}" has field arguments and cannot be used in order by expressions.

What it means

Thrown when the field used in an order-by expression declares field arguments. Fields with arguments require arguments to be evaluated, which cannot be done inside an ORDER BY clause, so such fields are rejected.

Source

Thrown at v3/crates/metadata-resolve/src/stages/order_by_expressions/types.rs:118

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct OrderByExpressionGraphqlConfig {
    pub expression_type_name: ast::TypeName,
}

#[derive(Debug, thiserror::Error)]
pub enum OrderByExpressionIssue {
    #[error("Duplicate order by expression found: {order_by_expression}")]
    DuplicateOrderByExpression {
        order_by_expression: Qualified<OrderByExpressionIdentifier>,
    },
    #[error(
        "Cannot order by array relationship {relationship_name} in order by expression {order_by_expression}"
    )]
    CannotOrderByAnArrayRelationship {
        order_by_expression: Qualified<OrderByExpressionIdentifier>,
        relationship_name: RelationshipName,
    },
    #[error(
        "The orderable field \"{field_name}\" has field arguments and cannot be used in order by expressions."
    )]
    OrderByFieldWithFieldArguments { field_name: FieldName },
}

impl ShouldBeAnError for OrderByExpressionIssue {
    fn should_be_an_error(&self, flags: &open_dds::flags::OpenDdFlags) -> bool {
        match self {
            OrderByExpressionIssue::DuplicateOrderByExpression { .. } => flags
                .contains(open_dds::flags::Flag::DisallowDuplicateNamesAcrossTypesAndExpressions),
            OrderByExpressionIssue::CannotOrderByAnArrayRelationship { .. } => {
                flags.contains(open_dds::flags::Flag::DisallowArrayRelationshipInOrderBy)
            }
            OrderByExpressionIssue::OrderByFieldWithFieldArguments { .. } => {
                flags.contains(open_dds::flags::Flag::DisallowOrderByFieldsWithFieldArguments)
            }
        }
    }

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Find the field named in the error and check its arguments in the type definition
  2. Remove the field from the order-by expression, or remove its arguments if they are not needed
  3. If arguments are optional and unused, define an argumentless variant of the field and order by that

Example fix

# before
fields:
  - name: displayName
    arguments:
      format: String
# after
fields:
  - name: displayName   # argumentless, usable in order_by
# (move the parameterized version to a separate field)
Defensive patterns

Strategy: validation

Validate before calling

const field = type.fields.find(f => f.name === fieldName);
if (field?.arguments?.length) skip(fieldName); // not orderable

Type guard

const hasNoArguments = (f) => !f.arguments || f.arguments.length === 0;

Prevention

When it happens

Trigger: Defining an order_by_expressions entry that orders by a field which has an arguments block in the type/command field definition; detected during the order_by_expressions metadata stage.

Common situations: Ordering by a computed/parameterized field (e.g. formattedDate(format: ...)); adding arguments to an existing field that is already used in an order-by expression; migrating fields to argumented versions during upgrade.

Related errors


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