-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
@cacheControl(inheritMaxAge: true)
(#5247)
Previously, the cache control logic treats root fields and fields that return object or interface types which don't declare `maxAge` specially: they are treated as uncachable (`maxAge` 0) by default. You can change that 0 to a different number with the `defaultMaxAge` option, but you can't just make them work like scalars and not affect the cache policy at all. This PR introduces a new argument to the directive: `@cacheControl(inheritMaxAge: true)`. If this is specified on an field returning a composite type (object, interface, or union) or on the composite type itself, and it does not specify its `maxAge` in some other way (on the return value's type or via `setCacheHint`), then the field is just ignored for the sake of calculating cache policy, instead of defaulting to `defaultMaxAge`. Note that this does *not* affect root fields (scalar or composite). You still need to make sure that every root field is declared as cachable to have a cachable operation. This just lets you say that a nested composite form is "part of" its parent for the purposes of caching, just like nested scalar fields are by default. The behavior described above (and looking on the field's return type for `@cacheControl` in the first place) previously applied to fields returning object and interface types (possibly nested in some layers of not-null and/or list-of). This PR makes things more consistent by treating the third composite type (unions) in the same way. One use case for this could be in federation: `buildFederatedSchema` could add this directive to all `@external` fields, since their values are typically provided directly in the arguments to the `Query._entities` field. This addresses concerns from #4162 and #3559.
- Loading branch information
Showing
8 changed files
with
434 additions
and
112 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.