facebook/relay · error

Fragment not found in IR.

Error message

Fragment {key:?} not found in IR.

What it means

Panic in add_related_nodes: while walking the dependency graph upward from a changed definition, the requested key was not present in the graph map. This means the caller passed a definition name that the dependency-analyzer never indexed — typically a fragment/operation referenced (e.g. via a spread) but missing from the IR passed to the analyzer, indicating an inconsistency between the computed dependencies and the supplied Program.

Solutions

  1. Verify the fragment referenced by the changed definition exists in the project's GraphQL documents (no typo or missing file in --src)
  2. Rebuild the dependency graph from the same Program/IR that produced the changed definition names
  3. Check custom transforms don't remove definitions that others still spread into
  4. Report a Relay compiler bug if it reproduces on unmodified code with repro steps
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at compiler/crates/dependency-analyzer/src/ir.rs:267 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/52040107f25fe887. Report an issue: GitHub.

Appendix: source

Thrown at compiler/crates/dependency-analyzer/src/ir.rs:267

    }
}

// From `key` of changed definition, recursively traverse up the dependency tree, and add all related nodes (ancestors
// of changed definitions which are not from base definitions, and all of their descendants) into the `result`
fn add_related_nodes(
    visited: &mut ExecutableDefinitionNameSet,
    result: &mut ExecutableDefinitionNameMap<ExecutableDefinition>,
    dependency_graph: &ExecutableDefinitionNameMap<Node>,
    base_definition_names: &ExecutableDefinitionNameSet,
    key: ExecutableDefinitionName,
) {
    if !visited.insert(key) {
        return;
    }

    let parents = match dependency_graph.get(&key) {
        None => {
            panic!("Fragment {key:?} not found in IR.");
        }
        Some(node) => &node.parents,
    };
    if parents.is_empty() {
        if !base_definition_names.contains(&key) {
            add_descendants(result, dependency_graph, key);
        }
    } else {
        for parent in parents {
            add_related_nodes(
                visited,
                result,
                dependency_graph,
                base_definition_names,
                *parent,
            );
        }
    }

View on GitHub (pinned to 668b1b85e0)