Skip to content

Validate that directive applications are on valid locations - #10277

Merged
glen-84 merged 3 commits into
mainfrom
gai/validate-directive-application-locations
Aug 21, 2026
Merged

glen-84 merged 3 commits into
mainfrom
gai/validate-directive-application-locations

Conversation

@glen-84

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

Copy link
Copy Markdown
Member

Summary

  • Adds DirectiveIsInValidLocationRule to HotChocolate.Types.Validation: a directive application at a location its definition does not declare is now reported as HCV0032. Applications without a definition are skipped, since DirectiveIsDefinedRule already reports those.
  • DirectiveEvent now carries the DirectiveLocation at which the directive is applied, supplied by SchemaValidator at each publish site, since the location cannot be inferred from the member alone (arguments and input fields are both IInputValueDefinition). This is a breaking change to the public DirectiveEvent record struct.
  • Apollo Federation preprocessing now attaches its synthesized @internal, @lookup, @is, @shareable, @require, and @external applications to the FusionBuiltIns.SourceSchemaDirectives definitions instead of detached placeholder definitions, so the applications carry the declared locations the new rule checks.

Test plan

  • New DirectiveIsInValidLocationRuleTests with a failing case per type-system location (schema, scalar, object, interface, union, enum, enum value, input object, input field, field, field argument, directive definition, and directive-definition argument), plus declared-locations, repeatable, and undefined-directive controls.
  • dotnet test src/HotChocolate/Core/test/Types.Validation.Tests: 632/632 pass.
  • dotnet test src/HotChocolate/Fusion/test/Fusion.Composition.Tests: 3160/3160 pass.

Copilot AI lite review requested due to automatic review settings August 21, 2026 13:29

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

Adds schema-validation coverage to ensure directives are only applied at locations declared by their definitions, and updates eventing + Fusion Federation preprocessing so synthesized directives carry correct declared locations for validation.

Changes:

  • Introduces DirectiveIsInValidLocationRule (HCV0032) and registers it in the default SchemaValidator rule set.
  • Extends DirectiveEvent to include the applied DirectiveLocation, and updates SchemaValidator to publish directive events with explicit locations.
  • Updates Fusion Apollo Federation transformations to attach synthesized directive applications to FusionBuiltIns.SourceSchemaDirectives definitions (instead of placeholder directive definitions).

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/HotChocolate/Fusion/src/Fusion.Composition/ApolloFederation/TransformRequiresToRequire.cs Uses built-in directive definitions for synthesized @require / @external applications so declared locations are available during validation.
src/HotChocolate/Fusion/src/Fusion.Composition/ApolloFederation/GenerateLookupFields.cs Uses built-in directive definitions for synthesized @internal, @lookup, @is, @shareable applications.
src/HotChocolate/Core/test/Types.Validation.Tests/SchemaValidatorTests.cs Updates default-rule registration expectations to include the new rule.
src/HotChocolate/Core/test/Types.Validation.Tests/Rules/DirectiveIsInValidLocationRuleTests.cs Adds targeted tests for valid/invalid directive placement across type-system locations.
src/HotChocolate/Core/src/Types.Validation/SchemaValidator.cs Publishes DirectiveEvent with explicit directive application locations across schema members.
src/HotChocolate/Core/src/Types.Validation/Rules/DirectiveIsUniqueRule.cs Updates directive-event deconstruction to account for the new location payload.
src/HotChocolate/Core/src/Types.Validation/Rules/DirectiveIsInValidLocationRule.cs Adds the new validation rule that emits HCV0032 for invalid directive application locations.
src/HotChocolate/Core/src/Types.Validation/Rules/DirectiveIsDefinedRule.cs Updates directive-event deconstruction to account for the new location payload.
src/HotChocolate/Core/src/Types.Validation/Properties/ValidationResources.resx Adds localized resource string for the new HCV0032 message.
src/HotChocolate/Core/src/Types.Validation/Properties/ValidationResources.Designer.cs Regenerates resource accessor for the new message string.
src/HotChocolate/Core/src/Types.Validation/Logging/LogEntryHelper.cs Adds log entry builder for “directive in invalid location” (HCV0032).
src/HotChocolate/Core/src/Types.Validation/Logging/LogEntryCodes.cs Adds HCV0032 constant.
src/HotChocolate/Core/src/Types.Validation/Events/ValidationEvents.cs Extends DirectiveEvent with DirectiveLocation to support location-aware rules.
Files not reviewed (1)
  • src/HotChocolate/Core/src/Types.Validation/Properties/ValidationResources.Designer.cs: Generated file

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

@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

98.6% of changed lines covered (71/72)

File Covered Changed Patch %
…/HotChocolate/Core/src/Types.Validation/SchemaValidator.cs 31 32 96.9% 🟡
…/Core/src/Types.Validation/Events/ValidationEvents.cs 2 2 100.0% 🟢
…/Core/src/Types.Validation/Logging/LogEntryHelper.cs 12 12 100.0% 🟢
…/Core/src/Types.Validation/Rules/DirectiveIsDefinedRule.cs 1 1 100.0% 🟢
…/src/Types.Validation/Rules/DirectiveIsInValidLocationRule.cs 11 11 100.0% 🟢
…/Core/src/Types.Validation/Rules/DirectiveIsUniqueRule.cs 1 1 100.0% 🟢
…/Fusion.Composition/ApolloFederation/GenerateLookupFields.cs 4 4 100.0% 🟢
…/ApolloFederation/TransformRequiresToRequire.cs 3 3 100.0% 🟢
…/Fusion/src/Fusion.Composition/SourceSchemaParser.cs 6 6 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "4a70274a152721b49e3e1e7e99f724a2fa1a91b3",
  "files": [
    { "path": "src/HotChocolate/Core/src/Types.Validation/SchemaValidator.cs", "ranges": [[252, 252]] }
  ]
}

Project coverage: 56.3% (264451/470033 lines)

@glen-84
glen-84 merged commit a79d0b4 into main Aug 21, 2026
151 checks passed
@glen-84
glen-84 deleted the gai/validate-directive-application-locations branch August 21, 2026 14:28
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.

2 participants