facebook/relay · error
Duplicate fragment definitions named {}: first one: {:?} s
Error message
Duplicate fragment definitions named {}:
first one: {:?}
second one: {:?}
What it means
Panic while constructing a Program::from_definitions: two fragment definitions with the same name were collected; the location of both declarations is printed. Fragments are stored in a name-keyed map, so a duplicate makes the IR ambiguous and the build aborts.
Source
Thrown at compiler/crates/graphql-ir/src/program.rs:62
let mut fragments = HashMap::default();
let mut seen_operation_loc = HashMap::new();
for definition in definitions {
match definition {
ExecutableDefinition::Operation(operation) => {
let loc = operation.name.location;
let name = operation.name.item;
if let Some(another) = seen_operation_loc.insert(name, loc) {
panic!(
"\nDuplicate operation definitions named {name}: \nfirst one: {loc:?}\nsecond one: {another:?}\n"
);
}
operations.push(Arc::new(operation)); // Keep the order the operations same as inputs.
}
ExecutableDefinition::Fragment(fragment) => {
let loc = fragment.name.location;
let name = fragment.name.item;
if let Some(another) = fragments.insert(name, Arc::new(fragment)) {
panic!(
"\nDuplicate fragment definitions named {}: \nfirst one: {:?}\nsecond one: {:?}\n",
name, loc, &another.name.location
);
}
}
}
}
Self {
schema,
fragments,
operations,
}
}
pub fn insert_fragment(&mut self, fragment: Arc<FragmentDefinition>) {
let name = fragment.name.item;
if let Some(previous) = self.fragments.insert(name, fragment) {
panic!(View on GitHub (pinned to 668b1b85e0)
Solutions
- Rename one of the fragments or consolidate them into a single definition
- Check for the same fragment file being included by overlapping source globs
- Move project-specific fragments under their project root so names don't collide across projects
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at compiler/crates/graphql-ir/src/program.rs:62 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of facebook/relay@668b1b85e0 (2026-09-02).
Data as JSON: /api/errors/547bca64a7767307.
Report an issue: GitHub.