{"record":{"id":"dfa213d4be01b3f7","repo":"facebook/relay","slug":"expect-fragment-to-exist","errorCode":null,"errorMessage":"Expect fragment to exist.","messagePattern":"Expect fragment to exist\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/crates/relay-transforms/src/root_variables.rs","lineNumber":268,"sourceCode":"            && let Some(relay_resolver_metadata) = RelayResolverMetadata::from(directive)\n        {\n            for arg in relay_resolver_metadata.field_arguments.iter() {\n                if let Value::Variable(var) = &arg.value.item\n                    && self.is_root_variable(var.name.item)\n                {\n                    self.record_root_variable_usage(&var.name, &var.type_);\n                }\n            }\n        }\n        self.default_visit_directive(directive);\n    }\n\n    fn visit_fragment_spread(&mut self, spread: &FragmentSpread) {\n        self.visit_directives(&spread.directives);\n        let fragment = self\n            .program\n            .fragment(spread.fragment.item)\n            .expect(\"Expect fragment to exist.\");\n\n        // Detect root variables being passed as the value of @arguments;\n        // recover the expected type from the corresponding argument definitions.\n        if !fragment.variable_definitions.is_empty() {\n            for arg in spread.arguments.iter() {\n                if let Value::Variable(var) = &arg.value.item\n                    && let Some(def) = fragment\n                        .variable_definitions\n                        .named(VariableName(arg.name.item.0))\n                    && self.is_root_variable(var.name.item)\n                {\n                    self.record_root_variable_usage(&var.name, &def.type_);\n                }\n            }\n        }\n\n        // Merge any root variables referenced by the spread fragment\n        // into this (parent) fragment's arguments.","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/compiler/crates/relay-transforms/src/root_variables.rs#L250-L286","documentation":"The root_variables transform resolves each fragment spread by looking the fragment definition up in the program and expects it to exist (\"Expect fragment to exist.\"). It needs the definition to read @arguments variable definitions and type-check root variables passed to the spread. A missing definition means the spread references a fragment that was never added to the compiled program.","triggerScenarios":"A fragment spread whose target fragment is absent from the program — compiling per-file so the spread's fragment lives in an uncompiled module, a typo'd fragment name that skipped earlier validation, or a transform order where fragments were pruned before root_variables runs.","commonSituations":"Per-document compilation instead of whole-program compilation; fragments declared in files excluded from the compiler's document list; monorepo setups where the include globs miss the fragment's module.","solutions":["Compile the entire program (all documents) together so every spread's fragment is present.","Check your relay compiler config (include/exclude globs, docs/extension) so the fragment's file is picked up.","Verify earlier validation passes (undefined fragment detection) run before root_variables.","If the fragment was intentionally removed, remove the stale spread from the operation."],"exampleFix":"// relay.config.js — before\ninclude: ['src/queries/**'],\n// after\ninclude: ['src/**'],  // ensure fragments referenced by queries are compiled","handlingStrategy":"validation","validationCode":"if program.fragment(spread.fragment.item).is_none() {\n    return Err(vec![Diagnostic::error(format!(\"Undefined fragment '{}'\", spread.fragment.item))]));\n}","typeGuard":"fn spread_resolvable(program: &Program, spread: &FragmentSpread) -> bool { program.fragment(spread.fragment.item).is_some() }","tryCatchPattern":"let Some(fragment) = program.fragment(spread.fragment.item) else { continue; };","preventionTips":["Include all fragment-defining files in the compiler's document set.","Run undefined-fragment validation before root_variables.","Avoid per-file compilation for programs with cross-file spreads."],"tags":["relay-compiler","missing-fragment","fragment-spread"],"backgroundTag":"relay-compiler-missing-fragment","analyzedSha":"668b1b85e06261aa3b58dabfc51f8b5524a70955","analyzedAt":"2026-09-02T19:57:20.783Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}