hasura/graphql-engine · error · ModelAggregateExpressionError

the aggregate expression '{aggregate_expression}' is used wi

Error message

the aggregate expression '{aggregate_expression}' is used with the model '{model_name}' but the {count_type} aggregate's return type ({count_return_type}) does not match the count aggregate scalar type defined by the data connector '{data_connector_name}': {expected_count_return_type}

What it means

The return type declared for a count aggregate does not match the scalar type the data connector declares for its count aggregate. The resolver compared the aggregate's QualifiedTypeName against the connector's DataConnectorScalarType and found a mismatch.

Source

Thrown at v3/crates/metadata-resolve/src/stages/models/error.rs:295

    )]
    CountReturnTypeMustBeInt {
        aggregate_expression: Qualified<AggregateExpressionName>,
        model_name: Qualified<ModelName>,
        count_type: aggregates::CountAggregateType,
        data_connector_name: Qualified<DataConnectorName>,
    },
    #[error(
        "the aggregate expression '{aggregate_expression}' is used with the model '{model_name}' but the {count_type} aggregate's return type ({count_return_type}) does not have a scalar type representation mapping to the '{data_connector_name}' data connector's count aggregate type '{data_connector_count_return_type}'"
    )]
    CountReturnTypeMappingMissing {
        model_name: Qualified<ModelName>,
        aggregate_expression: Qualified<AggregateExpressionName>,
        count_type: aggregates::CountAggregateType,
        count_return_type: QualifiedTypeName,
        data_connector_name: Qualified<DataConnectorName>,
        data_connector_count_return_type: DataConnectorScalarType,
    },
    #[error(
        "the aggregate expression '{aggregate_expression}' is used with the model '{model_name}' but the {count_type} aggregate's return type ({count_return_type}) does not match the count aggregate scalar type defined by the data connector '{data_connector_name}': {expected_count_return_type}"
    )]
    CountReturnTypeMappingMismatch {
        model_name: Qualified<ModelName>,
        aggregate_expression: Qualified<AggregateExpressionName>,
        count_type: aggregates::CountAggregateType,
        count_return_type: QualifiedTypeName,
        data_connector_name: Qualified<DataConnectorName>,
        expected_count_return_type: QualifiedTypeName,
    },
    #[error("{0}")]
    AggregateExpressionError(#[from] aggregates::AggregateExpressionError),
}

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Align the aggregate's return type with the connector's declared count type
  2. Update the connector capabilities block to declare the count type you actually use
  3. Re-sync metadata after upgrading the connector

Example fix

// before
count:
  output_type: scalar: Float
// after
count:
  output_type: scalar: BigInt  # matches connector's count type
Defensive patterns

Strategy: validation

Validate before calling

// assert the aggregate's declared return type equals the connector's count type
assert_eq!(model.count_output_type, connector.count_aggregate_type);

Prevention

When it happens

Trigger: Declaring count's output type as e.g. Float while the connector declares its count aggregate type as BigInt; mixing Int/BigInt between metadata and connector capabilities.

Common situations: Hand-written metadata where count returns a different numeric type than the connector's; connector version upgrades that changed the count scalar type.

Related errors


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