facebook/relay · error
apple not found
Error message
apple not found
What it means
Panic from `.expect("apple not found")` in `test_object_fields_sorted_alphabetically` (compiler/crates/schema-set/src/build_schema_document.rs:962). The test declares `type Foo` with fields `zebra`, `apple`, `mango` in non-alphabetical order, prints the schema SDL, and asserts the substring positions are sorted. The panic means the printed SDL contains no `apple` field — the type or its fields were dropped from the output, or the SDL text no longer declares that field.
Source
Thrown at compiler/crates/schema-set/src/build_schema_document.rs:962
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");
let mango_pos = sdl.find("mango").expect("mango not found");
let zebra_pos = sdl.find("zebra").expect("zebra not found");
assert!(
apple_pos < mango_pos && mango_pos < zebra_pos,
"Fields should be sorted: {}",
sdl,
);
}
// --- Interface ---
#[test]
fn test_interface_with_fields() {
let sdl = schema_sdl(indoc! {r#"
interface Node {
id: ID!
}
"#});View on GitHub (pinned to 668b1b85e0)
Solutions
- Print the failing `sdl` and check whether `type Foo` and its fields appear at all; if `Foo` is missing entirely, investigate why the printer emits unreachable types differently.
- Confirm the test SDL still declares `apple: Int` inside `type Foo` and the substring matches exactly.
- Inspect the field-printing/ordering logic in build_schema_document.rs (the sorted-fields printer) for regressions that skip fields.
- Swap `.expect` for a panic that includes the SDL so the actual output is visible on failure.
Example fix
// before
let apple_pos = sdl.find("apple").expect("apple not found");
// after
let apple_pos = sdl
.find("apple")
.unwrap_or_else(|| panic!("apple not found in SDL:\n{}", sdl)); Defensive patterns
Strategy: validation
Validate before calling
// Check all expected fields exist before asserting order:
for f in ["apple", "mango", "zebra"] {
assert!(sdl.contains(f), "SDL missing field '{}'\n{}", f, sdl);
} Type guard
fn prints_field(sdl: &str, field: &str) -> bool {
sdl.split_whitespace().any(|tok| tok.starts_with(field))
} Try / catch
let apple_pos = sdl
.find("apple")
.unwrap_or_else(|| panic!("apple not found; SDL:\n{}", sdl)); Prevention
- Pre-assert each expected substring before positional comparisons so the failure names the missing item.
- Keep test SDL fixtures and lookup strings in sync — update all lookups when editing the fixture.
- If printed output is unreachable-type-sensitive, route the type through the query root or configure the printer to emit all definitions.
- Use assertion messages that embed the full SDL for fast diagnosis.
When it happens
Trigger: Building a schema from SDL with `type Foo { zebra: String apple: Int mango: Boolean }` via the `schema_sdl` helper, calling `to_sdl_definition()`, and finding the field `apple` missing from the printed output (printer emits no fields, or emits a different type shape).
Common situations: A printer regression that drops object fields or the whole object type; the test SDL edited (field renamed/removed) without updating the assertion; field printing only for types reachable from the query root, and `Foo` being unreachable.
Related errors
AI-assisted analysis of facebook/relay@668b1b85e0 (2026-09-02).
Data as JSON: /api/errors/df44553797259e3b.
Report an issue: GitHub.