Skip to content

Prevent Cache-Control header from being set if response has errors#2715

Merged
abernix merged 5 commits into
apollographql:masterfrom
fabsrc:disable-cache-control-header-on-errors
May 24, 2019
Merged

Prevent Cache-Control header from being set if response has errors#2715
abernix merged 5 commits into
apollographql:masterfrom
fabsrc:disable-cache-control-header-on-errors

Conversation

@fabsrc

@fabsrc fabsrc commented May 23, 2019

Copy link
Copy Markdown
Contributor

Closes apollographql/apollo-cache-control#12

Adds a check for errors and for data before setting the Cache-Control header. This change is aligned with the logic in the apollo-server-plugin-response-cache package:

if (
response.errors ||
!response.data ||
!overallCachePolicy ||
overallCachePolicy.maxAge <= 0
) {
// This plugin never caches errors or anything without a cache policy.
//
// There are two reasons we don't cache errors. The user-level
// reason is that we think that in general errors are less cacheable
// than real results, since they might indicate something transient
// like a failure to talk to a backend. (If you need errors to be
// cacheable, represent the erroneous condition explicitly in data
// instead of out-of-band as an error.) The implementation reason is
// that this lets us avoid complexities around serialization and
// deserialization of GraphQL errors, and the distinction between
// formatted and unformatted errors, etc.
return;
}

@abernix abernix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this!

Comment thread packages/apollo-cache-control/src/__tests__/cacheControlExtension.test.ts Outdated
Comment thread packages/apollo-cache-control/src/index.ts Outdated
@abernix abernix dismissed their stale review May 23, 2019 16:04

Feedback addressed, one remaining question.

@abernix abernix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful. Thank you!

@abernix abernix merged commit d1a0d16 into apollographql:master May 24, 2019
@abernix abernix added this to the Release 2.6.0 milestone May 24, 2019
@fabsrc fabsrc deleted the disable-cache-control-header-on-errors branch May 24, 2019 15:06
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skip calculation of HTTP headers if GraphQL response includes errors

2 participants