{"record":{"id":"e65b2ef07d00f1e7","repo":"hasura/graphql-engine","slug":"fields-of-different-type-type1-and-type2-canno","errorCode":null,"errorMessage":"fields of different type {type1} and {type2} cannot be merged under the same alias: {alias}","messagePattern":"fields of different type (.+?) and (.+?) cannot be merged under the same alias: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/crates/graphql/lang-graphql/src/validation/error.rs","lineNumber":59,"sourceCode":"    #[error(\"an internal error occurred during validation: type lookup failed for {type_name}\")]\n    InternalTypeNotFound { type_name: ast::TypeName },\n    #[error(\n        \"an internal error occurred during validation: field {field_name} lookup failed for sub type '{sub_type_name}' of type '{type_name}'\"\n    )]\n    InternalNoFieldOnSubtype {\n        type_name: ast::TypeName,\n        sub_type_name: ast::TypeName,\n        field_name: ast::Name,\n    },\n    #[error(\n        \"different fields {field1} and {field2} cannot be merged under the same alias: {alias}\"\n    )]\n    FieldsConflictDifferentFields {\n        alias: ast::Alias,\n        field1: ast::Name,\n        field2: ast::Name,\n    },\n    #[error(\n        \"fields of different type {type1} and {type2} cannot be merged under the same alias: {alias}\"\n    )]\n    FieldsConflictDifferingTypes {\n        alias: ast::Alias,\n        type1: ast::Type,\n        type2: ast::Type,\n    },\n    #[error(\"cannot merge fields with different arguments on the same alias: {alias}\")]\n    FieldsConflictDifferingArguments {\n        alias: ast::Alias,\n        location1: Option<spanning::SourcePosition>,\n        location2: Option<spanning::SourcePosition>,\n    },\n    #[error(\"the string {str} in the provided json value is not a valid GraphQL name\")]\n    NotAValidName { str: String },\n    #[error(\"expected a value of type {expected_type} but found a value of type {actual_type}\")]\n    IncorrectFormat {\n        expected_type: &'static str,","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/graphql/lang-graphql/src/validation/error.rs#L41-L77","documentation":"Thrown by the FieldsCanMerge rule when two fields with the same response key (alias) have different return types in the schema, e.g. one selection of `a: name` (String) and another `a: age` types clashing, or the same field name returning incompatible types on different branches (fragments on different types). Merging would require serializing two incompatible types into one response key, so validation fails with both types and the alias.","triggerScenarios":"Aliasing fields of different GraphQL types to the same key within overlapping selections; spreading fragments on different object types (no shared interface) that each define a field with the same name but different types under the same alias; schema change altering a field's type so previously-mergeable selections now conflict.","commonSituations":"Union/parallel fragment spreads where same-named fields on different types diverge in type; schema evolution changing a field from `String` to `[String]` breaking merged selections; large generated queries combining fragment selections on intersecting types.","solutions":["Rename one alias so the two fields occupy different response keys","If both selections should merge, make the field types identical (fix schema or select the same field)","For same-named fields on different concrete types, select them in mutually exclusive fragments (`... on A`, `... on B`) so they never overlap"],"exampleFix":"// before\n{ x: user { name } x: item { title } }\n// after\n{ u: user { name } i: item { title } }","handlingStrategy":"validation","validationCode":"for (key, fields) in group_by_response_key(selection) { let mut types = fields.iter().map(|f| schema.field_type(&f.name)); assert!(all_same_type(&mut types), \"conflicting types under alias {key}\"); }","typeGuard":"fn mergeable(t1: &Type, t2: &Type) -> bool { t1 == t2 }","tryCatchPattern":"match validate(doc) { Err(Error::FieldsConflictDifferingTypes { alias, .. }) => rename_alias(alias), r => r }","preventionTips":["Alias fields of different types to different keys","Put same-named differing-typed fields in mutually exclusive typed fragments","Re-validate merged/generated queries after schema type changes"],"tags":["graphql","fields-merge","type-conflict","alias"],"backgroundTag":"graphql-fields-conflict","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}