facebook/relay · error
Can only insert '{}' once. Had {:?} and trying to insert {:?
Error message
Can only insert '{}' once. Had {:?} and trying to insert {:?}. What it means
Panic in Program::insert_fragment: a fragment was inserted under a name that already exists in the program's fragment map. The previous and new fragment locations are printed. This invariant check fires during compiler transforms that add fragments (e.g. refetchable/connection transforms) when they generate or copy a fragment whose name collides with an existing one.
Source
Thrown at compiler/crates/graphql-ir/src/program.rs:80
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!(
"Can only insert '{}' once. Had {:?} and trying to insert {:?}.",
name, previous, self.fragments[&name]
);
};
}
pub fn fragment(&self, name: FragmentDefinitionName) -> Option<&Arc<FragmentDefinition>> {
self.fragments.get(&name)
}
pub fn fragment_mut(
&mut self,
name: FragmentDefinitionName,
) -> Option<&mut Arc<FragmentDefinition>> {
self.fragments.get_mut(&name)
}
/// Searches for an operation by name.View on GitHub (pinned to 668b1b85e0)
Solutions
- Check custom transforms that call insert_fragment for name collisions with existing fragments
- Avoid defining a fragment whose name matches a compiler-generated one (e.g. from @refetchable or @connection)
- If it reproduces with plain Relay code, report a compiler issue with the fragment definitions involved
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at compiler/crates/graphql-ir/src/program.rs:80 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/dc5be1e95645ba79.
Report an issue: GitHub.