hasura/graphql-engine · error · AggregateBooleanExpressionError

the {count_type} aggregation cannot be compared to because i

Error message

the {count_type} aggregation cannot be compared to because it is not enabled on the aggregate expression '{aggregate_expression}'

What it means

Count-style aggregations on an aggregate expression can only be compared against when explicitly enabled on that aggregate expression in the metadata. This error occurs when a comparison references a count aggregate (per CountAggregateType) that the aggregate expression does not have enabled.

Source

Thrown at v3/crates/metadata-resolve/src/stages/aggregate_boolean_expressions/types.rs:201

    #[error(
        "type mismatch between the aggregation function '{aggregation_function_name}' (return type: '{aggregation_function_return_type}') and the specified boolean expression type '{boolean_expression_type}' (operand type: '{boolean_expression_operand_type}')"
    )]
    AggregationFunctionTypeMismatch {
        aggregation_function_name: AggregationFunctionName,
        aggregation_function_return_type: QualifiedTypeName,
        boolean_expression_type: BooleanExpressionTypeIdentifier,
        boolean_expression_operand_type: QualifiedTypeName,
    },

    #[error(
        "the aggregation function '{aggregation_function_name}' returns an array type ({aggregation_function_return_type}). Array types are not supported in aggregate comparisons"
    )]
    ComparisonAgainstArrayTypesNotSupported {
        aggregation_function_name: AggregationFunctionName,
        aggregation_function_return_type: QualifiedTypeReference,
    },

    #[error(
        "the {count_type} aggregation cannot be compared to because it is not enabled on the aggregate expression '{aggregate_expression}'"
    )]
    CountAggregateNotEnabled {
        count_type: CountAggregateType,
        aggregate_expression: Qualified<AggregateExpressionName>,
    },

    #[error(
        "type mismatch between the '{count_type}' aggregate (return type: '{count_return_type}') and the specified boolean expression type '{boolean_expression_type}' (operand type: '{boolean_expression_operand_type}')"
    )]
    CountAggregateTypeMismatch {
        count_type: CountAggregateType,
        count_return_type: QualifiedTypeName,
        boolean_expression_type: BooleanExpressionTypeIdentifier,
        boolean_expression_operand_type: QualifiedTypeName,
    },

    #[error(

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Enable the count aggregate (the specific CountAggregateType) on the aggregate expression in metadata
  2. If it was disabled intentionally, update the query/filter to use a different enabled aggregate
  3. Validate metadata after changes to catch disabled-aggregate references early

Example fix

// before
aggregate_expression: MyAgg  // count not enabled
filter: { count: { _gt: 10 } }

// after
aggregate_expression: MyAgg  // enable count aggregate
filter: { count: { _gt: 10 } }
Defensive patterns

Strategy: validation

Validate before calling

let enabled: HashSet<_> = agg_expr.enabled_count_aggregates.iter().collect();
assert!(enabled.contains(&count_type), "{count_type} not enabled on {}", agg_expr.name);

Type guard

fn count_enabled(agg: &AggregateExpression, t: CountAggregateType) -> bool {
    agg.enabled_count_aggregates.contains(&t)
}

Try / catch

match resolve(expr) {
    Err(ResolveError::CountAggregateNotEnabled { count_type, aggregate_expression }) => {
        // enable the count aggregate in metadata or drop the comparison
    }
    r => r,
}

Prevention

When it happens

Trigger: Filtering/comparing on a count aggregate (e.g. count or distinct_count) on an AggregateExpressionName whose metadata does not enable that count type for comparison; using a comparative aggregate on a count that was never configured.

Common situations: Hand-writing aggregate expression metadata and forgetting to enable the count aggregation; disabling a count aggregate in metadata while queries or other metadata still compare against it; version upgrades that changed which counts are enabled by default.

Related errors


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