{"record":{"id":"d027130c4ce3eb9f","repo":"facebook/relay","slug":"duplicate-fragment-definitions-named-first-o-d02713","errorCode":null,"errorMessage":"\nDuplicate fragment definitions named {}: \nfirst one: {:?}\nsecond one: {:?}\n","messagePattern":"\nDuplicate fragment definitions named (.+?): \nfirst one: (.+?)\nsecond one: (.+?)\n","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/crates/program-with-dependencies/src/program_with_dependencies.rs","lineNumber":136,"sourceCode":"                ExecutableDefinition::Operation(operation) => {\n                    let loc = operation.name.location;\n                    let name = operation.name.item;\n                    if let Some(another) = seen_operation_loc.insert(name, loc) {\n                        panic!(\n                            \"\\nDuplicate operation definitions named {}: \\nfirst one: {:?}\\nsecond one: {:?}\\n\",\n                            name, loc, another\n                        );\n                    }\n                    scoped_operations.push(Arc::new(operation)); // Keep the order the operations same as inputs.\n                }\n                ExecutableDefinition::Fragment(fragment) => {\n                    let loc = fragment.name.location;\n                    let name = fragment.name.item;\n                    let fragment_ref = Arc::new(fragment);\n                    if let Some(another) =\n                        seen_fragments_loc.insert(name, fragment_ref.name.location)\n                    {\n                        panic!(\n                            \"\\nDuplicate fragment definitions named {}: \\nfirst one: {:?}\\nsecond one: {:?}\\n\",\n                            name, loc, another\n                        );\n                    }\n                    scoped_fragments.insert(name, fragment_ref.clone()); // Keep the order the fragments same as inputs.\n                }\n            }\n        }\n\n        // Ensure there are no duplicate fragments referenced in the dependencies.\n        for (fragment_name, signature) in &dependencies {\n            let loc = signature.name.location;\n            if let Some(another) = seen_fragments_loc.insert(*fragment_name, loc)\n                && another != loc\n            {\n                panic!(\n                    \"\\nDuplicate fragment definitions named {}: \\nfirst one: {:?}\\nsecond one: {:?}\\n\",\n                    fragment_name, loc, another","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/compiler/crates/program-with-dependencies/src/program_with_dependencies.rs#L118-L154","documentation":"This panic comes from ProgramWithDependencies::from_definitions when two fragment definitions share the same name. The function builds a lookup of fragments by name and panics if a name is inserted twice, since the dependency-resolution pass requires fragment names to be unique to resolve references unambiguously.","triggerScenarios":"Calling ProgramWithDependencies::from_definitions with an iterator of FragmentDefinition where two fragments have identical names (checked via seen_fragments_loc while walking the input fragments).","commonSituations":"Merging schema/operation sources that both define the same fragment (e.g. duplicated .graphql files included twice via include! or glob), a script concatenating documents, or copy-pasting a fragment into a second file.","solutions":["Find the two fragment definitions with the reported locations and delete or rename one so fragment names are unique across the whole set passed to from_definitions.","If files are gathered by glob/directory scan, deduplicate the file list before parsing so the same document isn't parsed twice.","If fragments come from multiple sources, namespace fragment names per source (e.g. Prefix_fragmentName) to avoid collisions.","Upgrade to a compiler version or add a pre-pass that reports duplicates as diagnostics instead of panicking."],"exampleFix":"// before\nfragment UserFields on User { name }\n// in another file, duplicate\nfragment UserFields on User { name }\n// after\nfragment UserFields on User { name }\nfragment AdminUserFields on User { name }\n","handlingStrategy":"validation","validationCode":"fn validate_unique_fragments<'a>(frags: impl IntoIterator<Item = &'a FragmentDefinition>) -> Result<(), String> {\n    let mut seen = std::collections::HashSet::new();\n    for f in frags {\n        if !seen.insert(f.name.item.0) {\n            return Err(format!(\"duplicate fragment definition: {}\", f.name.item.0));\n        }\n    }\n    Ok(())\n}\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run a pre-pass validating fragment name uniqueness before invoking from_definitions.","Use unique per-file fragment naming conventions to avoid collisions across sources.","Deduplicate parsed documents when collecting .graphql files via glob.","Treat compiler panics as build failures and surface the two reported locations in CI output."],"tags":["graphql","fragment","duplicate-definition","panic"],"backgroundTag":"duplicate-definition","analyzedSha":"668b1b85e06261aa3b58dabfc51f8b5524a70955","analyzedAt":"2026-09-02T19:57:20.783Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}