Skip to content

fix: set no-store cache-control header when response has an error#8933

Merged
carodewig merged 8 commits intodevfrom
caroline/rh-1302
Mar 3, 2026
Merged

fix: set no-store cache-control header when response has an error#8933
carodewig merged 8 commits intodevfrom
caroline/rh-1302

Conversation

@carodewig
Copy link
Copy Markdown
Contributor

@carodewig carodewig commented Feb 27, 2026

If a subgraph encounters an error (ie a timeout, ratelimit, etc), and the response cache plugin was going to set a cache-control header, set no-store as the cache-control header instead.

Although this might be a bit wide-sweeping (ie there might be a legitimate issue with the subgraph and retrying the request would not help), it's better for the default to err on the side of not caching rather than caching bad data.


Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • PR description explains the motivation for the change and relevant context for reviewing
  • PR description links appropriate GitHub/Jira tickets (creating when necessary)
  • Changeset is included for user-facing changes
  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Metrics and logs are added3 and documented
  • Tests added and passing4
    • Unit tests
    • Integration tests
    • Manual tests, as necessary

Exceptions

Note any exceptions here

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. A lot of (if not most) features benefit from built-in observability and debug-level logs. Please read this guidance on metrics best-practices.

  4. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

carodewig and others added 5 commits February 27, 2026 11:53
…ns GraphQL errors

When a query spans multiple subgraphs and one of them returns an error
or times out, the final HTTP response was still carrying the successful
subgraph's Cache-Control header (e.g. max-age=1800, public). This
allowed intermediate caches (CDNs, NGINX) to cache and serve incomplete
or stale partial responses to other clients.

Fix the supergraph_service layer to check the CONTAINS_GRAPHQL_ERROR
context key before writing the Cache-Control header. If any GraphQL
errors are present in the response, write Cache-Control: no-store
instead of the merged subgraph cache control.

Add two regression tests:
- no_store_on_partial_subgraph_failure: one subgraph returns a GraphQL
  error while another returns cacheable data
- no_store_on_subgraph_timeout: one subgraph times out via traffic
  shaping while another returns cacheable data

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@carodewig carodewig requested a review from a team as a code owner February 27, 2026 20:35
@github-actions

This comment has been minimized.

@apollo-librarian
Copy link
Copy Markdown
Contributor

apollo-librarian bot commented Feb 27, 2026

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: e17a1ee632484f76b8f97c28
Build Logs: View logs


✅ AI Style Review — No Changes Detected

No MDX files were changed in this pull request.

Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@carodewig carodewig enabled auto-merge (squash) March 3, 2026 16:51
@carodewig carodewig merged commit 16c30ed into dev Mar 3, 2026
13 checks passed
@carodewig carodewig deleted the caroline/rh-1302 branch March 3, 2026 17:11
@abernix abernix mentioned this pull request Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants