hasura/graphql-engine · error · OrderByExpressionIssue

Duplicate order by expression found: {order_by_expression}

Error message

Duplicate order by expression found: {order_by_expression}

What it means

Thrown when two order-by expressions in the metadata resolve to the same qualified OrderByExpressionIdentifier, i.e. the same order-by expression is defined more than once for a type. Identifiers must be unique within the metadata namespace.

Source

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

    pub order_by_expression_identifier: Qualified<OrderByExpressionIdentifier>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct OrderableRelationship {
    /// order_by_expression is optional.
    /// If not present we will use order_by_expression from the model
    /// that the relationship targets.
    pub order_by_expression: Option<Qualified<OrderByExpressionName>>,
}

#[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 {

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Search all order_by_expressions definitions for the identifier shown in the error
  2. Delete or rename the duplicate so each identifier is defined exactly once
  3. If merging files/subgraphs, ensure expression names are unique per subgraph

Example fix

# before
order_by_expressions:
  - name: authorByName
    ...
  - name: authorByName   # duplicate
# after
order_by_expressions:
  - name: authorByName
    ...
  - name: authorByEmail
    ...
Defensive patterns

Strategy: validation

Validate before calling

const seen = new Set();
for (const e of order_by_expressions) {
  const key = `${e.subgraph}::${e.name}`;
  if (seen.has(key)) throw new Error(`duplicate ${key}`);
  seen.add(key);
}

Prevention

When it happens

Trigger: Defining two entries in order_by_expressions metadata with the same name/subgraph/type combination, or including the same expression file twice, causing duplicate Qualified<OrderByExpressionIdentifier> keys during resolution.

Common situations: Copy-pasting an order-by expression block and forgetting to rename it; merging metadata files that both define the same expression; YAML anchors/duplicates silently producing two identical entries.

Related errors


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