New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cache control plugin: set cache-control: no-store
by default
#6986
Conversation
As pointed out in #2605, browsers cache many GET requests by default, so "not cacheable" shouldn't be the same as "don't set a cache-control header". This PR makes the backwards-incompatible change to the cache control plugin to make it always set the cache-control header to something if it is enabled (with calculateHttpHeaders not set to false), perhaps `no-store`. (If some other plugin or error already set the header, it does not override it with `no-store`.) To restore AS3 behavior: ApolloServerPluginCacheControl({ calculateHttpHeaders: 'if-cacheable' }) Fixes #2605.
✅ Deploy Preview for apollo-server-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 2359cb0:
|
Going forward with this; post-merge review. |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to version-4, this PR will be updated.⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ `version-4` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `version-4`.⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ # Releases ## @apollo/server-integration-testsuite@4.0.0-rc.16 ### Patch Changes - [#6986](#6986) [`db5d715a3`](db5d715) Thanks [@glasser](https://github.com/glasser)! - The cache control plugin sets `cache-control: no-store` for uncacheable responses. Pass `calculateHttpHeaders: 'if-cacheable'` to the cache control plugin to restore AS3 behavior. - Updated dependencies \[[`db5d715a3`](db5d715)]: - @apollo/server@4.0.0-rc.16 ## @apollo/server@4.0.0-rc.16 ### Patch Changes - [#6986](#6986) [`db5d715a3`](db5d715) Thanks [@glasser](https://github.com/glasser)! - The cache control plugin sets `cache-control: no-store` for uncacheable responses. Pass `calculateHttpHeaders: 'if-cacheable'` to the cache control plugin to restore AS3 behavior. Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@@ -331,14 +331,21 @@ The effect of setting `honorSubgraphCacheControlHeader` to `false` is to have no | |||
|
|||
## Caching with a CDN | |||
|
|||
Whenever Apollo Server sends an operation response that has a non-zero `maxAge`, it includes a `Cache-Control` HTTP header that describes the response's cache policy. | |||
Whenever Apollo Server sends an operation response that is cacheable, it includes a `Cache-Control` HTTP header that describes the response's cache policy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glasser Additionally, it now also sets the cache-control
header when it's not cacheable as well. We do go on to clarify this below, but the way this is written leads me to think it's only set when cacheable.
@@ -852,13 +870,18 @@ export function defineIntegrationTestSuiteHttpServerTests( | |||
expect(res.body.data).toEqual({ | |||
pooks: [{ title: 'pook', books }], | |||
}); | |||
expect(res.headers['cache-control']).toBeUndefined; | |||
expect(res.headers['cache-control']).toBeUndefined(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yikes, good catch
@@ -873,6 +896,23 @@ export function defineIntegrationTestSuiteHttpServerTests( | |||
}); | |||
}); | |||
|
|||
it('cache-control not set without any hints', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might update the description of this test? cache-control
is set to no-store
.
Implementation LGTM, with a few docs/test related suggestions within. |
Based on review by @trevor-scheer.
As pointed out in #2605, browsers cache many GET requests by default, so "not cacheable" shouldn't be the same as "don't set a cache-control header". This PR makes the backwards-incompatible change to the cache control plugin to make it always set the cache-control header to something if it is enabled (with calculateHttpHeaders not set to false), perhaps
no-store
. (If some other plugin or error already set the header, it does not override it withno-store
.)To restore AS3 behavior:
Fixes #2605.