hasura/graphql-engine · error · Error
different fields {field1} and {field2} cannot be merged unde
Error message
different fields {field1} and {field2} cannot be merged under the same alias: {alias} What it means
Thrown by the FieldsCanMerge validation rule when two fields responded to the same alias resolve to different field names, e.g. `{ a: petName, a: product }`. Since only one value can be returned per alias, differing field names cannot be merged and the document is rejected with the alias and both field names.
Source
Thrown at v3/crates/graphql/lang-graphql/src/validation/error.rs:51
},
#[error("no such field on type {type_name}: {field_name}")]
NoFieldOnType {
type_name: ast::TypeName,
field_name: ast::Name,
},
#[error("no such type defined in the document: {0}")]
UnknownType(ast::TypeName),
#[error("an internal error occurred during validation: type lookup failed for {type_name}")]
InternalTypeNotFound { type_name: ast::TypeName },
#[error(
"an internal error occurred during validation: field {field_name} lookup failed for sub type '{sub_type_name}' of type '{type_name}'"
)]
InternalNoFieldOnSubtype {
type_name: ast::TypeName,
sub_type_name: ast::TypeName,
field_name: ast::Name,
},
#[error(
"different fields {field1} and {field2} cannot be merged under the same alias: {alias}"
)]
FieldsConflictDifferentFields {
alias: ast::Alias,
field1: ast::Name,
field2: ast::Name,
},
#[error(
"fields of different type {type1} and {type2} cannot be merged under the same alias: {alias}"
)]
FieldsConflictDifferingTypes {
alias: ast::Alias,
type1: ast::Type,
type2: ast::Type,
},
#[error("cannot merge fields with different arguments on the same alias: {alias}")]
FieldsConflictDifferingArguments {
alias: ast::Alias,View on GitHub (pinned to 724551b9ae)
Solutions
- Give each field a unique alias (`{ x: fieldA, y: fieldB }`)
- If the fields are meant to be the same, correct the duplicate so both selections use the same field name
- Audit fragments combined into one operation for alias collisions
Example fix
// before
{ x: petName, x: product }
// after
{ pet: petName, prod: product } Defensive patterns
Strategy: validation
Validate before calling
let mut keys = HashSet::new(); for f in all_fields_in_scope(selection) { let key = f.alias.as_ref().unwrap_or(&f.name); assert!(keys.insert(key.clone()), "duplicate response key {key} with different fields"); } Type guard
fn same_field(a: &Field, b: &Field) -> bool { a.name == b.name } Try / catch
match validate(doc) { Err(Error::FieldsConflictDifferentFields { alias, .. }) => rename_alias(alias), r => r } Prevention
- Use unique aliases for distinct fields
- Lint for duplicate response keys in merged selections
- When combining fragments, audit overlapping field names
When it happens
Trigger: Aliasing two different fields to the same alias in one selection set (`{ x: fieldA, x: fieldB }`), including across fragments spread into the same scope; copy-paste of selections while forgetting to update the alias; conflicting fields defined in different fragments that are spread together.
Common situations: Merging fragments from different modules that happen to alias different fields identically; query builders deduplicating by alias and silently collapsing distinct fields; refactoring that renames a field but keeps the alias.
Related errors
- validation failed: {0}
- Unexpected value: expecting {expected_kind:}, but found: {fo
- '{name:}' is not a valid GraphQL name.
- '{alias:} is not a valid alias
- {value} is not a valid limit value
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/5690e8c5e8081aaa.
Report an issue: GitHub.