{"record":{"id":"9c5ca816c6a821e4","repo":"hasura/graphql-engine","slug":"the-return-type-used-on-the-count-type-aggregate-9c5ca8","errorCode":null,"errorMessage":"the return type used on the {count_type} aggregate ({return_type}) must be an integer type","messagePattern":"the return type used on the (.+?) aggregate \\((.+?)\\) must be an integer type","errorType":"validation","errorClass":"AggregateExpressionError","httpStatus":null,"severity":"error","filePath":"v3/crates/metadata-resolve/src/stages/aggregates/types.rs","lineNumber":291,"sourceCode":"        name: Qualified<AggregateExpressionName>,\n        data_connector_name: Qualified<DataConnectorName>,\n        field_name: FieldName,\n    },\n\n    #[error(\"graphql config error in {aggregate_expression_name}: {graphql_config_error}\")]\n    GraphqlConfigError {\n        aggregate_expression_name: Qualified<AggregateExpressionName>,\n        graphql_config_error: graphql_config::GraphqlConfigError,\n    },\n\n    #[error(\"the return type used on the {count_type} aggregate ({return_type}) is unknown\")]\n    UnknownCountReturnType {\n        aggregate_expression_name: Qualified<AggregateExpressionName>,\n        count_type: CountAggregateType,\n        return_type: QualifiedTypeName,\n    },\n\n    #[error(\n        \"the return type used on the {count_type} aggregate ({return_type}) must be an integer type\"\n    )]\n    InvalidCountReturnType {\n        aggregate_expression_name: Qualified<AggregateExpressionName>,\n        count_type: CountAggregateType,\n        return_type: QualifiedTypeName,\n    },\n}\n\nimpl ContextualError for AggregateExpressionError {\n    fn create_error_context(&self) -> Option<error_context::Context> {\n        None\n    }\n}\n\n#[derive(Debug, Eq, PartialEq, Copy, Clone, derive_more::with_trait::Display)]\npub enum CountAggregateType {\n    #[display(\"count\")]","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/metadata-resolve/src/stages/aggregates/types.rs#L273-L309","documentation":"During metadata resolution of aggregate expressions, the return type explicitly configured for a count aggregate was resolved successfully but is not an integer type (e.g. String, Boolean, Float, or a non-integer custom scalar). Count aggregates must return an integer type so the GraphQL schema is coherent, so validation fails with this error.","triggerScenarios":"Setting the return type of a count or distinct_count aggregate expression to a non-integer scalar (String, Float, Boolean, UUID, etc.) in the metadata.","commonSituations":"Copy-pasting an aggregate definition from a sum/avg aggregate that legitimately returns Float and forgetting to change the return type; assuming count returns the same type as the counted column; metadata migrations that changed scalar types underneath existing count aggregates.","solutions":["Change the count aggregate's return type to an integer scalar such as Int or BigInt (BigInt is typical for counts).","If a custom scalar is used, make sure it maps to an integer-backed GraphQL type.","Re-apply the metadata after the fix."],"exampleFix":"// before\n- name: count_users\n  count:\n    return_type: { name: Float, arguments: [] }\n// after\n- name: count_users\n  count:\n    return_type: { name: BigInt, arguments: [] }","handlingStrategy":"validation","validationCode":"const INTEGER_TYPES: &[&str] = &[\"Int\", \"BigInt\"];\nfn is_valid_count_return(rt: &str) -> bool { INTEGER_TYPES.contains(&rt) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use Int/BigInt (or an integer-backed custom scalar) for count aggregate return types.","Code-review aggregate definitions when copying from sum/avg aggregates.","Automate a metadata lint rule that count return types are integer scalars."],"tags":["hasura","metadata","aggregates","count","graphql"],"backgroundTag":"schema-validation-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}