facebook/relay · error

extend type A not found

Error message

extend type A not found

What it means

Panic from `.expect("extend type A not found")` in `test_extensions_print_after_definitions` (compiler/crates/schema-set/src/build_schema_document.rs:944), in the same test as error 161. The printed SDL from `set.to_sdl_definition()` contains no `extend type A` substring. The test's purpose is that base definitions print before extensions, so if the extension is missing entirely the ordering guarantee cannot be verified and the library panics via `.expect`.

Source

Thrown at compiler/crates/schema-set/src/build_schema_document.rs:944

    fn test_extensions_print_after_definitions() {
        let doc = parse_schema_document(
            indoc! {r#"
                extend type A implements B {
                  id: ID
                }

                interface B {
                  id: ID
                }
            "#},
            SourceLocationKey::generated(),
        )
        .unwrap();
        let set = SchemaSet::from_schema_documents_with_extensions(&[], &[doc]).unwrap();
        let sdl = format!("{}", set.to_sdl_definition());

        let interface_pos = sdl.find("interface B").expect("interface B not found");
        let extension_pos = sdl.find("extend type A").expect("extend type A not found");
        assert!(
            interface_pos < extension_pos,
            "Definitions should print before extensions: {}",
            sdl,
        );
    }

    #[test]
    fn test_object_fields_sorted_alphabetically() {
        let sdl = schema_sdl(indoc! {r#"
            type Foo {
              zebra: String
              apple: Int
              mango: Boolean
            }
        "#});
        // Fields should be sorted alphabetically
        let apple_pos = sdl.find("apple").expect("apple not found");

View on GitHub (pinned to 668b1b85e0)

Solutions

  1. Print the actual `sdl` output and inspect how `type A`/`extend type A` is rendered; adjust the assertion if formatting changed but semantics are intact.
  2. Check that `from_schema_documents_with_extensions` retains extension documents and that `to_sdl_definition` iterates them; if extensions are being folded into base definitions, that is a printer regression to fix in build_schema_document.rs.
  3. Ensure the base type `A` exists (the test relies on `A` being defined only via extension, which some validators reject — consider defining `type A` base too if the builder drops orphan extensions).
  4. Replace `.expect` with a panic that dumps the SDL so future failures are self-explanatory.

Example fix

// before
let extension_pos = sdl.find("extend type A").expect("extend type A not found");
// after
let extension_pos = sdl
    .find("extend type A")
    .unwrap_or_else(|| panic!("extend type A not found in SDL:\n{}", sdl));
Defensive patterns

Strategy: validation

Validate before calling

// Validate the SDL contains the extension before comparing positions:
assert!(
    sdl.contains("extend type A"),
    "SDL missing 'extend type A'; extensions may be merged or dropped:\n{}",
    sdl
);

Type guard

fn prints_extension(sdl: &str, type_name: &str) -> bool {
    sdl.contains(&format!("extend type {}", type_name))
}

Try / catch

let extension_pos = sdl
    .find("extend type A")
    .unwrap_or_else(|| panic!("extend type A not found; SDL was:\n{}", sdl));

Prevention

When it happens

Trigger: Calling `SchemaSet::from_schema_documents_with_extensions(&[], &[doc])` where `doc` declares `extend type A implements B`, then printing with `to_sdl_definition()` and finding the extension absent — e.g. the printer merged the extension into a single `type A` definition, dropped extensions that reference not-yet-defined interfaces, or the extension document was parsed into a bucket that `to_sdl_definition` ignores.

Common situations: A printer change that flattens type extensions into base type definitions; extensions silently discarded during schema-set build because the base type `A` is not itself defined in the non-extension documents; test input edited so the extension no longer matches the searched string.

Related errors


AI-assisted analysis of facebook/relay@668b1b85e0 (2026-09-02). Data as JSON: /api/errors/320010f74b984edd. Report an issue: GitHub.