Skip to content

Move non-repeatable directive uniqueness to schema validation - #10200

Merged
glen-84 merged 1 commit into
mainfrom
gai/directive-is-unique-rule
Aug 5, 2026
Merged

glen-84 merged 1 commit into
mainfrom
gai/directive-is-unique-rule

Conversation

@glen-84

@glen-84 glen-84 commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary

  • Types.Validation gains DirectiveIsUniqueRule (HCV0031), which reports a non-repeatable directive applied more than once at the same location, one entry per directive name however many times it repeats.
  • The Mutable SchemaParser no longer throws when an extension re-applies a non-repeatable directive. MergeDirectives is removed and all three extension paths append like every other path, so the invalid state is representable and reported by validation instead of aborting the parse.
  • SchemaValidator publishes directive events for the schema definition, so SCHEMA-location applications reach the directive rules. Apollo Federation source schemas apply @link to the schema without declaring it, so a @link definition is registered for them; RemoveFederationInfrastructure already strips both the definition and its applications during preprocessing.

Test plan

  • DirectiveIsUniqueRuleTests covers every location the validator traverses in one case — schema, type, output field, argument, input field, enum value, directive definition, and directive-definition argument — plus a repeatable directive, three applications collapsing to one entry, the type-extension path, and a spec directive.
  • The three SchemaParserTests extension cases assert both applications are kept instead of asserting a throw. The argument path had no coverage before.
  • Full suites run for Types.Validation (141), Types.Mutable (88), and Fusion.Composition (740), plus Types.Abstractions, Adapters.OpenApi, Fusion.Utilities, and Fusion.Execution as the remaining consumers of Types.Validation and the Mutable parser.

Copilot AI review requested due to automatic review settings August 5, 2026 14:17
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate labels Aug 5, 2026

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

Moves enforcement of non-repeatable directive uniqueness from the mutable schema parse/merge phase into the central schema validation pipeline, allowing invalid (but representable) schema states to be parsed and then surfaced consistently as validation errors.

Changes:

  • Added DirectiveIsUniqueRule (HCV0031) and wired it into SchemaValidator, including publishing directive events for the schema definition.
  • Updated the mutable SchemaParser extension paths to append directives (instead of throwing) and adjusted parser tests accordingly.
  • Improved Fusion Federation source parsing by registering an explicit @link directive definition so schema-level applications bind and can be validated/processed consistently.

Reviewed changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
website/content/docs/fusion/source-schema-extensions.md Updates docs to reflect parser now keeps duplicate non-repeatable directives and relies on validation to fail composition.
src/HotChocolate/Mutable/test/Types.Mutable.Tests/SchemaParserTests.cs Updates/extends tests to assert duplicates are retained for extension scenarios (field, argument, directive definition).
src/HotChocolate/Mutable/src/Types.Mutable/Serialization/SchemaParser.cs Removes directive merge-time uniqueness throwing and switches extension paths to append directives.
src/HotChocolate/Mutable/src/Types.Mutable/Properties/MutableResources.resx Removes the no-longer-used parser error string for duplicate non-repeatable directives.
src/HotChocolate/Mutable/src/Types.Mutable/Properties/MutableResources.Designer.cs Removes the generated accessor for the deleted parser resource string.
src/HotChocolate/Fusion/src/Fusion.Composition/SourceSchemaParser.cs Registers @link for federation sources and keeps @requires registration conditional; supports schema-level directive validation.
src/HotChocolate/Fusion/src/Fusion.Composition/Definitions/LinkMutableDirectiveDefinition.cs Adds a minimal mutable directive definition for Apollo Federation @link (schema location, repeatable).
src/HotChocolate/Core/test/Types.Validation.Tests/Rules/DirectiveIsUniqueRuleTests.cs Adds coverage for DirectiveIsUniqueRule across all traversed locations and repeatable/spec cases.
src/HotChocolate/Core/src/Types.Validation/SchemaValidator.cs Adds DirectiveIsUniqueRule to default rules and publishes directive events for the schema definition.
src/HotChocolate/Core/src/Types.Validation/Rules/DirectiveIsUniqueRule.cs Implements the non-repeatable directive uniqueness validation rule.
src/HotChocolate/Core/src/Types.Validation/Properties/ValidationResources.resx Adds the localized message template for the new uniqueness validation error.
src/HotChocolate/Core/src/Types.Validation/Properties/ValidationResources.Designer.cs Adds the generated accessor for the new validation resource string.
src/HotChocolate/Core/src/Types.Validation/Logging/LogEntryHelper.cs Adds DirectiveNotUnique log entry builder and unifies directive member naming for related messages.
src/HotChocolate/Core/src/Types.Validation/Logging/LogEntryCodes.cs Adds HCV0031 code constant for directive uniqueness violations.
Files not reviewed (2)
  • src/HotChocolate/Core/src/Types.Validation/Properties/ValidationResources.Designer.cs: Generated file
  • src/HotChocolate/Mutable/src/Types.Mutable/Properties/MutableResources.Designer.cs: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Patch coverage

98.7% of changed lines covered (74/75)

File Covered Changed Patch %
…/Core/src/Types.Validation/Logging/LogEntryHelper.cs 19 20 95.0% 🟡
…/Core/src/Types.Validation/Rules/DirectiveIsUniqueRule.cs 21 21 100.0% 🟢
…/HotChocolate/Core/src/Types.Validation/SchemaValidator.cs 2 2 100.0% 🟢
…/Definitions/LinkMutableDirectiveDefinition.cs 21 21 100.0% 🟢
…/Fusion/src/Fusion.Composition/SourceSchemaParser.cs 8 8 100.0% 🟢
…/Mutable/src/Types.Mutable/Serialization/SchemaParser.cs 3 3 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "f1f20e92964ab665297e3ec9f272580aa169ce90",
  "files": [
    { "path": "src/HotChocolate/Core/src/Types.Validation/Logging/LogEntryHelper.cs", "ranges": [[641, 641]] }
  ]
}

Project coverage: 54.4% (242365/445717 lines)

@glen-84
glen-84 merged commit 29ac99d into main Aug 5, 2026
150 checks passed
@glen-84
glen-84 deleted the gai/directive-is-unique-rule branch August 5, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants