Skip to content
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

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

Merged
merged 5 commits into from
May 24, 2019
Merged

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

merged 5 commits into from
May 24, 2019

Conversation

fabsrc
Copy link
Contributor

@fabsrc fabsrc commented May 23, 2019

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;
}

Copy link
Member

@abernix abernix left a comment

Choose a reason for hiding this comment

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

Thanks for opening this!

@abernix abernix dismissed their stale review May 23, 2019 16:04

Feedback addressed, one remaining question.

Copy link
Member

@abernix abernix left a comment

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