Repository navigation
Fix type-level cache control for wrapped and abstract return types - #10835
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 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-levelsharedMaxAgecan be incorrectly lowered by a type-levelmaxAge; the corresponding possible-object extraction also needs this precedence guard.CacheControlConstraintsComputer.cs:116— moderate (1 vote): return-typevaryvalues 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
Contributor
Patch coverage100.0% of changed lines covered (27/27)
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
This was referenced Nov 10, 2026
This was referenced Nov 19, 2026
fix(deps): Bump Basic.Reference.Assemblies.Net100 and 32 others
AdCodicem/AdCodicem.ValueObjects#262
Closed
This was referenced Nov 26, 2026
fix(deps): Bump Basic.Reference.Assemblies.Net100 and 43 others
AdCodicem/AdCodicem.ValueObjects#274
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@cacheControlapplies to fields that return it through non-null and list wrappers, soAccount,Account!, and[Account!]!all take the settings ofAccount.maxAgeorsharedMaxAgedeclared on the field still takes precedence. Otherwise the lowest lifetime among the return type and its object types applies, andscope: PRIVATEandvaryapply from any of them.ApplyDefaultsenabled, a root field or a field a lookup brings in whose@cacheControlsets 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.private, gainVarynames, get a shorter lifetime, or gain aCache-Controlheader it did not have.Test plan
HttpCachingTestscases, sent as GET requests:T!,[T!]!, and a nested non-null field.varyreturned throughT!.HttpCachingTestscases for the defaults, sent as GET requests: a root field that declares onlyscopeand returnsT!,[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.FusionCachingTestscases, sent as GET requests: a private type returned throughT!and[T!]!, a union field whose selection names only another member, an interface field, and a root field that declares onlyscopeand returnsT!or[T!]!. They fail without the change.HotChocolate.Caching.TestsandHotChocolate.Fusion.Caching.Testson net8.0, net9.0, net10.0, and net11.0.