Fix SchemaParser to handle semantically invalid type usage#9746
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens schema parsing so that semantically invalid type usage (e.g., using an input object type in an output field position, even when wrapped in list/non-null) is detected early with clearer errors, and prevents follow-on schema validation noise when parsing already failed.
Changes:
- Update
SchemaParserto validate input/output type semantics viaIsInputType()/IsOutputType()(instead of relying on interface casts that wrappers can satisfy even when the named type is invalid). - Add Fusion composition tests covering invalid type usage for fields, input object fields, arguments, and directive arguments.
- Skip schema validation in
SourceSchemaParserwhen parsing has already produced errors to avoid cascading validation errors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/HotChocolate/Mutable/src/Types.Mutable/Serialization/SchemaParser.cs | Enforces semantic input/output type correctness when building/merging fields and arguments. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaParserTests.cs | Adds regression tests ensuring clear errors for invalid type usage and no cascading validation logs. |
| src/HotChocolate/Fusion/src/Fusion.Composition/SourceSchemaParser.cs | Avoids running schema validation when parsing already logged errors. |
Comments suppressed due to low confidence (1)
src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaParserTests.cs:128
Assert.DoesNotContain(log, ...)is redundant aftervar entry = Assert.Single(log);(the log is already proven to have exactly one entry). Removing the extra assertion will simplify the test without reducing coverage.
Assert.True(result.IsFailure);
var entry = Assert.Single(log);
Assert.Equal(
"Invalid GraphQL in source schema. Exception message: "
+ "The field 'Query.exportFoos' must return an output type..",
entry.Message);
Assert.DoesNotContain(log, e => e.Code == "HCV0001");
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced May 20, 2026
This was referenced May 30, 2026
This was referenced Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.