Repository navigation
Opt-in whole-response cache for GraphQL queries - #2649
Merged
Merged
Conversation
An operation named in graphql_cacheable_operations has its whole response stored in the shared cache for graphql_response_cache_ttl seconds, so a repeated identical request skips the database and the field engine. Off by default; responses with errors are not stored.
The response is stored under the latest non-availability history id, read before the query runs, so any later node, link or tag change makes it unreachable. The TTL becomes a backstop rather than the staleness bound.
✅ Deploy Preview for thriving-cassata-78ae72 canceled.
|
shangyian
marked this pull request as ready for review
October 24, 2026 07:58
[Medium impact] The changes since the previous review appear safe to merge. SummaryAdds opt-in caching for whole GraphQL responses.
No new actionable issues were found in the changes since the previous review. The earlier threads were unnumbered, so they have no numbered classifications.
|
…collections Pick the operation with graphql-core (operationName, or the only operation), accept queries only, and key on the printed document so formatting does not matter. The data version now also covers availability for a document that selects it and collections for one that lists them.
…response The history version is now the latest id plus the count of recent rows, from one statement, so a row that commits after one with a higher id changes it. A response is skipped if "errors" appears anywhere in its body, not just in the last 4096 bytes.
Parse the HTTP body with the router's own parse_http_body, so _cacheable_request receives a typed GraphQLRequestData instead of an arbitrary JSON value, and a batch (a list) is excluded by type.
Pick the operation with graphql-core's get_operation_ast, look for availability and listCollections in the query text instead of walking the document, and move the collections signature into its own function.
Replace the history and collections versions with a version in the shared cache that a committing session replaces. The history id version never changed on data with old, very large ids. Import HTTPException from cross_web and upgrade strawberry-graphql.
…sions, and read cacheable queries from the writer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Some GraphQL queries are expensive and identical across callers. This PR lets a deployment serve those responses from the shared cache.
What it does
graphql_cacheable_operationslists operation names to cache. It is empty by default, which turns the feature off. Only named queries are eligible.How it's invalidated
Test Plan
make checkpassesmake testshows 100% unit test coverageDeployment Plan