Skip to content

Fix SchemaParser to handle semantically invalid type usage#9746

Merged
tobias-tengler merged 1 commit into
mainfrom
tte/harden-schema-parser
May 20, 2026
Merged

Fix SchemaParser to handle semantically invalid type usage#9746
tobias-tengler merged 1 commit into
mainfrom
tte/harden-schema-parser

Conversation

@tobias-tengler

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings May 20, 2026 08:39

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 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 SchemaParser to validate input/output type semantics via IsInputType() / 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 SourceSchemaParser when 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 after var 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.

@tobias-tengler tobias-tengler merged commit 9cd9563 into main May 20, 2026
145 checks passed
@tobias-tengler tobias-tengler deleted the tte/harden-schema-parser branch May 20, 2026 08:51
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.

2 participants