{"record":{"id":"a4bf84055dd80422","repo":"hasura/graphql-engine","slug":"the-aggregate-defined-on-the-relationship-relatio","errorCode":null,"errorMessage":"The aggregate defined on the relationship {relationship_name} on type {type_name} has an error: {error}","messagePattern":"The aggregate defined on the relationship (.+?) on type (.+?) has an error: (.+?)","errorType":"validation","errorClass":"RelationshipError","httpStatus":null,"severity":"error","filePath":"v3/crates/metadata-resolve/src/stages/object_relationships/error.rs","lineNumber":134,"sourceCode":"        relationship_name: RelationshipName,\n        data_connector_name: Qualified<DataConnectorName>,\n    },\n    #[error(\n        \"The target data connector {data_connector_name} for relationship {relationship_name} on type {type_name} has not defined any capabilities\"\n    )]\n    NoRelationshipCapabilitiesDefined {\n        type_name: Qualified<CustomTypeName>,\n        relationship_name: RelationshipName,\n        data_connector_name: Qualified<DataConnectorName>,\n    },\n    #[error(\n        \"The relationship {relationship_name} on type {type_name} defines an aggregate, but aggregates can only be used with array relationships, not object relationships\"\n    )]\n    AggregateIsOnlyAllowedOnArrayRelationships {\n        type_name: Qualified<CustomTypeName>,\n        relationship_name: RelationshipName,\n    },\n    #[error(\n        \"The aggregate defined on the relationship {relationship_name} on type {type_name} has an error: {error}\"\n    )]\n    ModelAggregateExpressionError {\n        type_name: Qualified<CustomTypeName>,\n        relationship_name: RelationshipName,\n        error: models::ModelsError, // ideally, this would return the more accurate\n                                    // `ModelAggregateExpressionError` instead\n    },\n    #[error(\n        \"The source field '{source_field_name}' of type '{source_field_type}' in the relationship '{relationship_name}' on type '{source_type}' cannot be mapped to the target argument '{target_argument_name}' of type '{target_argument_type}' on the target model '{target_model_name}' because their types are incompatible\"\n    )]\n    ModelArgumentTargetMappingTypeMismatch {\n        source_type: Qualified<CustomTypeName>,\n        relationship_name: RelationshipName,\n        source_field_name: FieldName,\n        source_field_type: QualifiedTypeReference,\n        target_model_name: Qualified<ModelName>,\n        target_argument_name: ArgumentName,","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/metadata-resolve/src/stages/object_relationships/error.rs#L116-L152","documentation":"The aggregate expression attached to a relationship failed to resolve; the underlying error comes from the models resolution stage (ModelsError) and is embedded in this message. Typical causes are invalid operator references, unknown fields, or type mismatches in the aggregate expression.","triggerScenarios":"Defining an aggregate whose expression (functions/operators, field references, or result type) cannot be resolved against the target model's supported aggregate capabilities.","commonSituations":"Using an aggregate function the target connector/model doesn't support; referencing a non-numeric field with a numeric aggregate; malformed expression trees.","solutions":["Read the embedded {error} detail — it carries the actual ModelsError reason","Fix the aggregate expression per that inner error (correct function, field, or type)","Verify the target model/connector supports the aggregate functions you use"],"exampleFix":"// before\naggregates:\n  total:\n    count: { field: created_at }   # unsupported/invalid usage\n// after\naggregates:\n  total:\n    count: {}\n  latest:\n    max: { field: created_at }","handlingStrategy":"try-catch","validationCode":"// best effort: ensure referenced aggregate fields exist on the target model\nconst modelFields = new Set(models[targetModel].fields.map(f => f.name));\nfor (const agg of Object.values(rel.aggregates ?? {})) {\n  for (const f of agg.fields ?? []) if (!modelFields.has(f)) throw new Error(`aggregate references unknown field ${f}`);\n}","typeGuard":null,"tryCatchPattern":"try { await applyMetadata(md); } catch (e) { if (/aggregate .* has an error/.test(e.message)) { /* inspect embedded ModelsError detail */ } throw e; }","preventionTips":["Only use aggregate functions the target connector advertises","Test aggregate expressions against the target model in a scratch project first"],"tags":["metadata","relationships","aggregates","expression","model"],"backgroundTag":"aggregate-expression-invalid","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}