Restore GraphQL caching after query failures - #201
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR ensures Craft Cloud’s StaticCache component restores the original enableGraphqlCaching setting even if GraphQL execution fails and the normal afterExecute cleanup doesn’t run, preventing GraphQL result caching from remaining disabled for the rest of the request.
Changes:
- Restore
enableGraphqlCachingand clear the internal$graphqlCachingStackduringResponse::EVENT_AFTER_PREPAREwhen a stack leak is detected. - Extend the unit test to simulate a failure path and assert GraphQL caching is restored and the stack is emptied.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/StaticCache.php |
Restores the original GraphQL caching config and clears the stack in handleAfterPrepareWebResponse() to guarantee cleanup even when query execution doesn’t reach the normal unwind path. |
tests/unit/StaticCacheTest.php |
Adds coverage for the failure/cleanup scenario by forcing a non-OK response and asserting config restoration + stack reset. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
timkelty
marked this pull request as ready for review
August 28, 2026 16:53
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.
An exception during GraphQL execution can skip the normal cleanup, leaving GraphQL result caching disabled for the rest of the request.
Ensure the request restores its original GraphQL caching setting even when execution fails.
Follow-up to #200 and #200 (comment).