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

Add no-cache headers to PersistedQuery error responses #2452

Conversation

ryandrewjohnson
Copy link
Contributor

@ryandrewjohnson ryandrewjohnson commented Mar 15, 2019

Issue:

Since both PersistedQueryNotSupportedError and PersistedQueryNotFoundError are considered HttpGraphQL errors they will respond with an http status code of 200 with no cache-control headers set. This causes issues when you have a CDN like CloudFront sitting in front of your Apollo Server as it will hold onto these errors, which results in subsequent responses being served the cached error response.

Fix:

When either PersistedQueryNotSupportedError or PersistedQueryNotFoundError is thrown the following cache-control header is added to the response preventing it from being cached:

'Cache-Control': 'private, no-cache, must-revalidate'

For more details please see the Spectrum chat with discussion on the issue:
https://spectrum.chat/apollo/apollo-server/cloudfront-caching-persistedquerynotfound-error-responses~b615361e-53f2-4771-a3d2-d04fb9349246

TODO:

  • Update CHANGELOG.md with your change (include reference to issue & this PR)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass

@apollo-cla
Copy link

@ryandrewjohnson: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

@ryandrewjohnson ryandrewjohnson force-pushed the add-nocache-headers-persistedquery-errors branch from c7559b2 to da24aa8 Compare March 15, 2019 16:06
@ryandrewjohnson ryandrewjohnson changed the title add no-cache headers to PersistedQuery error responses Add no-cache headers to PersistedQuery error responses Mar 15, 2019
@mikelau13
Copy link

thx Ryan, that's exactly what I need!

@ryandrewjohnson
Copy link
Contributor Author

@abernix @martijnwalraven any chance this can make it in for the next release? This addresses the bug we discussed on Spectrum https://spectrum.chat/apollo/apollo-server/cloudfront-caching-persistedquerynotfound-error-responses~b615361e-53f2-4771-a3d2-d04fb9349246.

We have an app in production that we've had to remove Persisted Query functionality due to this bug. In the interim we've had to revert back to plain GET requests, with the plan to activate persisted queries again once this is merged/released.

@ryandrewjohnson
Copy link
Contributor Author

@abernix really hoping to get some feedback on this?

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.

Apologies for the delays! I've left a couple comments, but this seems generally correct to me. I'll do a bit more looking into it before merging, but I'd be keen on putting this into an alpha of Apollo Server 2.5.0 for testing (see #2482).

packages/apollo-server-errors/src/index.ts Outdated Show resolved Hide resolved
packages/apollo-server-core/src/runHttpQuery.ts Outdated Show resolved Hide resolved
@ryandrewjohnson
Copy link
Contributor Author

@abernix thanks for taking a look at this! That would be amazing if it could make it in for the alpha release of alpha 2.5.0.

@abernix abernix changed the base branch from master to release-2.5.0 April 4, 2019 11:16
@abernix abernix added this to the Release 2.5.0 milestone Apr 4, 2019
@abernix abernix self-assigned this Apr 4, 2019
@ryandrewjohnson
Copy link
Contributor Author

@abernix just pushed latest fix. This should be good to merge now - thanks!

@abernix abernix merged commit 10a9083 into apollographql:release-2.5.0 Apr 5, 2019
@abernix
Copy link
Member

abernix commented Apr 5, 2019

Thanks for this PR!

It's been published in apollo-server@2.5.0-alpha.3 — and the various integrations like apollo-server-express, apollo-server-hapi, etc. — of the same version!

@ryandrewjohnson
Copy link
Contributor Author

Thanks for this PR!

It's been published in apollo-server@2.5.0-alpha.3 — and the various integrations like apollo-server-express, apollo-server-hapi, etc. — of the same version!

@abernix any guesstimate on when this release will officially drop?

@ryandrewjohnson ryandrewjohnson deleted the add-nocache-headers-persistedquery-errors branch April 5, 2019 16:54
@abernix
Copy link
Member

abernix commented Apr 6, 2019

The more feedback about the alpha the more confident we can be with promoting it to “latest”. Anything that would be keeping you from trying the alpha?

@ryandrewjohnson
Copy link
Contributor Author

@abernix I think we could probably put the alpha version in, and see how it goes. Are there any known breaking changes?

@abernix
Copy link
Member

abernix commented Apr 8, 2019

@ryanmaxwell Nope! These are the changes at the current time: https://github.com/apollographql/apollo-server/milestone/17?closed=1

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 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.

4 participants