Skip to content

Fix undefined union member type crash in mutable schema parser - #10274

Merged
michaelstaib merged 2 commits into
mainfrom
mst/fix-composition-undefined-type-crash
Aug 20, 2026
Merged

michaelstaib merged 2 commits into
mainfrom
mst/fix-composition-undefined-type-crash

Conversation

@michaelstaib

@michaelstaib michaelstaib commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Fixes #10268

Copilot AI lite review requested due to automatic review settings August 20, 2026 17:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves schema parsing and Fusion composition error handling by converting previously crashy/misleading failure modes (missing root types / missing union member types) into consistent SchemaInitializationExceptions, and by scoping composition logging so a previously-failed schema on a shared CompositionLog doesn’t prevent later schemas from being parsed/preprocessed/validated.

Changes:

  • Add root type resolution and union member resolution guards in SchemaParser to throw deterministic initialization errors instead of crashing or misclassifying missing types.
  • Introduce ScopedCompositionLog and update Fusion parser/preprocessor to rely on per-schema scoped errors rather than the shared parent log’s HasErrors.
  • Add/extend tests in Mutable + Fusion to cover undefined root types, undefined union member types, and “earlier schema failed on shared log” scenarios.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/HotChocolate/Mutable/test/Types.Mutable.Tests/SchemaParserTests.cs Adds regression tests for undefined root types and union member types.
src/HotChocolate/Mutable/src/Types.Mutable/Serialization/SchemaParser.cs Resolves root types safely and validates union member types, throwing specific initialization exceptions.
src/HotChocolate/Mutable/src/Types.Mutable/Properties/MutableResources.resx Adds new localized messages for root type/union member missing or invalid.
src/HotChocolate/Mutable/src/Types.Mutable/Properties/MutableResources.Designer.cs Regenerates resource accessors for the new messages.
src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaPreprocessorTests.cs Adds test ensuring preprocessing succeeds for later schema despite earlier shared-log failure.
src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaParserTests.cs Adds tests for undefined root/union member types + shared-log failure behavior.
src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SchemaComposerTests.cs Adds test asserting only the invalid schema is reported when a valid schema follows it.
src/HotChocolate/Fusion/src/Fusion.Composition/SourceSchemaPreprocessor.cs Uses scoped log to avoid earlier shared-log errors forcing current preprocessing to fail.
src/HotChocolate/Fusion/src/Fusion.Composition/SourceSchemaParser.cs Uses scoped log so parsing/validation isn’t blocked by prior schemas’ errors in a shared log.
src/HotChocolate/Fusion/src/Fusion.Composition/Logging/ScopedCompositionLog.cs New wrapper log that forwards to parent while tracking scoped entries and scoped HasErrors.
Files not reviewed (1)
  • src/HotChocolate/Mutable/src/Types.Mutable/Properties/MutableResources.Designer.cs: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +556 to +560
Assert.Equal(
"Invalid GraphQL in source schema. Exception message: "
+ "The query root type 'Query' is not defined..",
entry.Message);
Assert.Equal("A", entry.Schema?.Name);
Comment on lines +634 to +638
Assert.Equal(
"Invalid GraphQL in source schema. Exception message: "
+ "The Union type 'Thing' cannot include the undefined type 'Widget'..",
entry.Message);
Assert.Equal("A", entry.Schema?.Name);
Comment on lines +1192 to +1201
// assert
Assert.True(result.IsFailure);
var error = Assert.Single(result.Errors);
Assert.Equal("Source schema parsing failed.", error.Message);
var entry = Assert.Single(log);
Assert.Equal("A", entry.Schema?.Name);
Assert.Equal(
"Invalid GraphQL in source schema. Exception message: "
+ "The query root type 'Query' is not defined..",
entry.Message);
Comment on lines +1198 to +1201
Assert.Equal(
"Invalid GraphQL in source schema. Exception message: "
+ "The query root type 'Query' is not defined..",
entry.Message);
@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

94.9% of changed lines covered (56/59)

File Covered Changed Patch %
…/src/Fusion.Composition/Logging/ScopedCompositionLog.cs 13 15 86.7% 🟡
…/Fusion/src/Fusion.Composition/SourceSchemaParser.cs 7 8 87.5% 🟡
…/Fusion/src/Fusion.Composition/SourceSchemaPreprocessor.cs 6 6 100.0% 🟢
…/Mutable/src/Types.Mutable/Serialization/SchemaParser.cs 30 30 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "06c9e83bde8e37734cc3ba1d08ac962a5637689e",
  "files": [
    { "path": "src/HotChocolate/Fusion/src/Fusion.Composition/Logging/ScopedCompositionLog.cs", "ranges": [[16, 16], [33, 33]] },
    { "path": "src/HotChocolate/Fusion/src/Fusion.Composition/SourceSchemaParser.cs", "ranges": [[96, 96]] }
  ]
}

Project coverage: 56.0% (261536/466695 lines)

@michaelstaib
michaelstaib merged commit dfd52c6 into main Aug 20, 2026
152 checks passed
@michaelstaib
michaelstaib deleted the mst/fix-composition-undefined-type-crash branch August 20, 2026 18:15
This was referenced Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Composition crashes with a raw KeyNotFoundException when a schema definition names an undefined root type, and reports later source schemas as failed

2 participants