{"record":{"id":"4738e302f5388737","repo":"hasura/graphql-engine","slug":"the-aggregation-function-aggregation-function-wa","errorCode":null,"errorMessage":"The aggregation function {aggregation_function} was used on the model object type and not on a model field. Aggregation functions operate on columns, not rows","messagePattern":"The aggregation function (.+?) was used on the model object type and not on a model field\\. Aggregation functions operate on columns, not rows","errorType":"exception","errorClass":"InternalDeveloperError","httpStatus":null,"severity":"error","filePath":"v3/crates/graphql/ir/src/error.rs","lineNumber":239,"sourceCode":"\n    #[error(\n        \"The aggregation function {aggregation_function} operating over the {aggregate_operand_type} type is missing a data connector mapping for {data_connector_name}\"\n    )]\n    DataConnectorAggregationFunctionNotFound {\n        aggregate_operand_type: QualifiedTypeName,\n        aggregation_function: AggregationFunctionName,\n        data_connector_name: Qualified<DataConnectorName>,\n    },\n\n    #[error(\n        \"A field ({field_name}) with an AggregatableField annotation was found on a scalar-typed ({aggregate_operand_type}) operand's selection set\"\n    )]\n    AggregatableFieldFoundOnScalarTypedOperand {\n        field_name: FieldName,\n        aggregate_operand_type: QualifiedTypeName,\n    },\n\n    #[error(\n        \"The aggregation function {aggregation_function} was used on the model object type and not on a model field. Aggregation functions operate on columns, not rows\"\n    )]\n    ColumnAggregationFunctionUsedOnModelObjectType {\n        aggregate_operand_type: QualifiedTypeName,\n        aggregation_function: AggregationFunctionName,\n    },\n\n    #[error(\"{0}\")]\n    PlanInternalDeveloperError(plan::InternalDeveloperError),\n}\n\n#[derive(Debug, thiserror::Error)]\npub enum InternalEngineError {\n    #[error(\"serialization error: {0}\")]\n    SerializationError(#[from] json::Error),\n\n    #[error(\"error from normalized AST: {0}\")]\n    IRConversionError(#[from] gql::normalized_ast::Error),","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/graphql/ir/src/error.rs#L221-L257","documentation":"An aggregation function was applied at the model object-type level instead of on a model field. Aggregations operate on columns (field values), not rows, so aggregating the object itself is meaningless and rejected during IR resolution.","triggerScenarios":"Placing an aggregation like count/sum directly on the model type node rather than under a field in an aggregate query; malformed aggregate queries from hand-built query strings.","commonSituations":"Misunderstanding the aggregate query shape and nesting the aggregation one level too high; migrating handwritten queries from another GraphQL dialect with different aggregate syntax.","solutions":["Move the aggregation function under a specific field/column of the model","Use the generated *_aggregate query structure as a template","Check the aggregate query shape in the docs for your model"],"exampleFix":"# before\nquery { songs { agg { avg } } }\n# after\nquery { songs_aggregate { agg { avg { duration } } } }","handlingStrategy":"validation","validationCode":"// Ensure aggregations are applied to a field, not the model node\nassert(aggregateTarget.kind === 'field');","typeGuard":"const isFieldLevelAggregation = (node) => node.path.at(-1)?.kind === 'field';","tryCatchPattern":"// On error, rewrite query so the aggregation sits under a specific column","preventionTips":["Copy the *_aggregate query shape from docs/codegen","Never aggregate the object node itself"],"tags":["graphql","aggregation","query-shape"],"backgroundTag":"aggregation-on-object-type","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}