Skip to content

Resolve _service.sdl once per request without internal directives - #10831

Merged
glen-84 merged 2 commits into
mainfrom
gai/apollo-federation-service-sdl
Nov 9, 2026
Merged

glen-84 merged 2 commits into
mainfrom
gai/apollo-federation-service-sdl

Conversation

@glen-84

@glen-84 glen-84 commented Nov 9, 2026

Copy link
Copy Markdown
Member

Summary

  • _service.sdl formats the schema once per schema instance and returns that string from then on, instead of printing the schema each time the field resolves.
  • The SDL leaves out internal directives such as @authorize and @allowAnonymous, as the schema download does. DisableInternalDirectives brings them back in both places. Composition that reads a Hot Chocolate subgraph through _service { sdl } no longer receives that subgraph's @authorize directives; the subgraph still enforces them.
  • A request resolves sdl once. A further sdl selection in the same request, through another alias of sdl or of _service, returns an error on its path, and since both fields are non-null the response has data: null.
  • The migration guide's "Internal directives hidden from schema endpoint" section now mentions _service { sdl }.

Test plan

  • New ServiceTypeTests cases: the SDL of a schema with an [Authorize] field leaves out @authorize and includes it with DisableInternalDirectives, GetSdl returns the same string for one schema, two aliases of sdl and two _service aliases that select sdl return one error and data: null, and two requests on one executor both resolve the SDL. The directive, caching, and alias cases fail without the change.
  • Ran HotChocolate.ApolloFederation.Tests on net8.0, net9.0, net10.0, and net11.0.
  • Ran on net10.0: HotChocolate.ApolloFederation.ImplementationFirst.Tests, HotChocolate.Fusion.Composition.ApolloFederation.Tests, HotChocolate.Fusion.Connectors.ApolloFederation.Tests, HotChocolate.Fusion.Connectors.ApolloFederation.Compliance.Tests, which reads _service { sdl } over HTTP, and the Apollo Federation classes of HotChocolate.Fusion.AspNetCore.Tests.
  • Prettier, cspell, and markdownlint on the migration guide.

Copilot AI lite review requested due to automatic review settings November 9, 2026 13:10
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate labels Nov 9, 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.

🟢 Approval recommended

No active review issues remain, and the change is accompanied by targeted coverage and documentation for its SDL caching, filtering, and duplicate-resolution behavior.

No open issues 🎉

1 file not reviewed
  • src/HotChocolate/ApolloFederation/src/ApolloFederation/Properties/FederationResources.Designer.cs: Generated file
What changed in this PR

Updates Apollo Federation’s _service { sdl } handling to cache formatted SDL per schema, hide internal directives by default, and reject duplicate SDL resolutions within a request.

Changes:

  • Added schema-scoped SDL caching with ConditionalWeakTable.
  • Added internal-directive filtering that respects DisableInternalDirectives.
  • Added request-level duplicate-resolution protection and localized error handling.
  • Expanded tests and migration documentation.
File Summary
website/​content/​docs/​hotchocolate/​migrating/​migrate-from-15-to-16.md Documents internal directive filtering for _service { sdl }.
src/​HotChocolate/​ApolloFederation/​test/​ApolloFederation.Tests/​ServiceTypeTests.cs Tests directive visibility, caching, duplicate selections, aliases, and repeated requests.
src/​HotChocolate/​ApolloFederation/​src/​ApolloFederation/​Types/​ServerFields.cs Tracks SDL resolution per request and reports duplicate resolutions.
src/​HotChocolate/​ApolloFederation/​src/​ApolloFederation/​Types/​_Service.cs Caches formatted SDL per schema and excludes internal directives by default.
src/​HotChocolate/​ApolloFederation/​src/​ApolloFederation/​ThrowHelper.cs Adds the duplicate SDL resolution exception helper.
src/​HotChocolate/​ApolloFederation/​src/​ApolloFederation/​Properties/​FederationResources.resx Adds the duplicate-resolution error message resource.
src/​HotChocolate/​ApolloFederation/​src/​ApolloFederation/​Properties/​FederationResources.Designer.cs Exposes the generated resource accessor.
src/​HotChocolate/​ApolloFederation/​src/​ApolloFederation/​FederationTypeInterceptor.cs Installs the guarded SDL resolver on the _Service.sdl field.
src/​HotChocolate/​ApolloFederation/​src/​ApolloFederation/​FederationContextData.cs Defines the request context key used to track SDL resolution.

Review effort: Lite

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (34/34)

File Covered Changed Patch %
…/src/ApolloFederation/FederationTypeInterceptor.cs 13 13 100.0% 🟢
…/ApolloFederation/src/ApolloFederation/ThrowHelper.cs 4 4 100.0% 🟢
…/ApolloFederation/src/ApolloFederation/Types/ServerFields.cs 11 11 100.0% 🟢
…/ApolloFederation/src/ApolloFederation/Types/_Service.cs 6 6 100.0% 🟢

Project coverage: 59.5% (321736/541021 lines)

# Conflicts:
#	src/HotChocolate/ApolloFederation/src/ApolloFederation/FederationContextData.cs
@glen-84
glen-84 merged commit 25f0144 into main Nov 9, 2026
157 checks passed
@glen-84
glen-84 deleted the gai/apollo-federation-service-sdl branch November 9, 2026 17:58
glen-84 added a commit that referenced this pull request Nov 9, 2026
glen-84 added a commit that referenced this pull request Nov 9, 2026
glen-84 added a commit that referenced this pull request Nov 10, 2026
glen-84 added a commit that referenced this pull request Nov 10, 2026
This was referenced Nov 19, 2026
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