Skip to content

Fix type-level cache control for wrapped and abstract return types - #10835

Merged
glen-84 merged 3 commits into
mainfrom
gai/cache-control-wrapped-and-abstract-types
Nov 9, 2026
Merged

glen-84 merged 3 commits into
mainfrom
gai/cache-control-wrapped-and-abstract-types

Conversation

@glen-84

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

Copy link
Copy Markdown
Member

Summary

  • A type's @cacheControl applies to fields that return it through non-null and list wrappers, so Account, Account!, and [Account!]! all take the settings of Account.
  • For a field that returns an interface or union, the settings of every object type that implements it or belongs to it apply as well, whether or not the operation selects fields of that object type.
  • A maxAge or sharedMaxAge declared on the field still takes precedence. Otherwise the lowest lifetime among the return type and its object types applies, and scope: PRIVATE and vary apply from any of them.
  • With ApplyDefaults enabled, a root field or a field a lookup brings in whose @cacheControl sets no lifetime takes its return type's lifetime through wrappers too, and gets the default only when the return type sets none. An interface or union return type sets a lifetime when it sets one itself, or when every object type that implements it or belongs to it does.
  • The server and the gateway share this calculation. A response that selects such a field can become private, gain Vary names, get a shorter lifetime, or gain a Cache-Control header it did not have.
  • The server and Fusion cache-control pages describe how the return type's settings apply, to the defaults as well.

Test plan

  • New HttpCachingTests cases, sent as GET requests:
    • A private type returned through T!, [T!]!, and a nested non-null field.
    • A union field whose selection names the private member, and one that names only another member.
    • An interface field implemented by a private type.
    • A type lifetime and vary returned through T!.
    • A union field without a lifetime, whose members declare different lifetimes.
    • A union field whose lifetime is higher than a member's.
  • All but the last fail without the change. The last checks that the field's lifetime stays ahead of the members'.
  • New HttpCachingTests cases for the defaults, sent as GET requests: a root field that declares only scope and returns T!, [T!]!, a union whose members all declare a lifetime, and a union with a member that declares none. All but the last fail without the change. The last checks that the default still applies.
  • New FusionCachingTests cases, sent as GET requests: a private type returned through T! and [T!]!, a union field whose selection names only another member, an interface field, and a root field that declares only scope and returns T! or [T!]!. They fail without the change.
  • Ran HotChocolate.Caching.Tests and HotChocolate.Fusion.Caching.Tests on net8.0, net9.0, net10.0, and net11.0.
  • Prettier, cspell, and markdownlint on both docs pages.

Copilot AI lite review requested due to automatic review settings November 9, 2026 13:11
@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 blocking issues remain, so the expanded cache-control behavior is supported by server and Fusion coverage and documentation.

No open issues 🎉

What changed in this PR

This pull request extends cache-control evaluation so type-level policies apply through list/non-null wrappers and across interface or union return types for both Hot Chocolate servers and Fusion gateways.

Changes:

  • Resolve cache-control metadata from named return types behind wrappers.
  • Apply policies from interfaces, unions, and their possible object types.
  • Add server and Fusion HTTP caching tests.
  • Document the expanded behavior for server and Fusion caching.

Review findings:

  • CacheControlConstraintsComputer.cs:116 — moderate (1 vote): field-level sharedMaxAge can be incorrectly lowered by a type-level maxAge; the corresponding possible-object extraction also needs this precedence guard.
  • CacheControlConstraintsComputer.cs:116 — moderate (1 vote): return-type vary values can be lost when the field supplies all cache-control values.
  • HttpCachingTests.cs:474, 507, 529, 554, 578 — nit (1 vote each): response assertions should use CookieCrumble snapshots instead of hand-maintained JSON strings.
File Description
website/​content/​docs/​hotchocolate/​server/​cache-control.md Documents server-side cache-control inheritance for wrapped and abstract return types.
website/​content/​docs/​fusion/​cache-control.md Documents corresponding Fusion cache-control behavior.
src/​HotChocolate/​Fusion/​test/​Fusion.Caching.Tests/​FusionCachingTests.cs Adds Fusion gateway coverage for wrapped and abstract return types.
src/​HotChocolate/​Caching/​test/​Caching.Tests/​HttpCachingTests.cs Adds server HTTP caching coverage for wrapped, interface, union, lifetime, scope, and Vary behavior.
src/​HotChocolate/​Caching/​src/​Caching.Core/​CacheControlConstraintsComputer.cs Computes cache constraints from named return types and possible object types.

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 (27/27)

File Covered Changed Patch %
…/Caching/src/Caching.Core/CacheControlConstraintsComputer.cs 27 27 100.0% 🟢

Project coverage: 59.5% (321954/541205 lines)

# Conflicts:
#	src/HotChocolate/Caching/src/Caching.Core/CacheControlConstraintsComputer.cs
#	src/HotChocolate/Caching/test/Caching.Tests/HttpCachingTests.cs
#	src/HotChocolate/Fusion/test/Fusion.Caching.Tests/FusionCachingTests.cs

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

The recorded review state reports no active issues for this focused cache-control update.

No open issues 🎉

Review effort: Lite

@glen-84
glen-84 merged commit fe989eb into main Nov 9, 2026
160 checks passed
@glen-84
glen-84 deleted the gai/cache-control-wrapped-and-abstract-types branch November 9, 2026 19:09
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