Skip to content

Instantly share code, notes, and snippets.

@xuxucode
Created January 3, 2018 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuxucode/1ea55ba024eeb5b1bf4e6734f4dc9ce8 to your computer and use it in GitHub Desktop.
Save xuxucode/1ea55ba024eeb5b1bf4e6734f4dc9ce8 to your computer and use it in GitHub Desktop.
Prevent caching if there is an error occurs
diff --git a/src/GraphQL/Execution/QueryProcessor.php b/src/GraphQL/Execution/QueryProcessor.php
index 941b664..a2a7f27 100644
--- a/src/GraphQL/Execution/QueryProcessor.php
+++ b/src/GraphQL/Execution/QueryProcessor.php
@@ -100,9 +100,9 @@ class QueryProcessor {
$metadata->addCacheableDependency($container->get('metadata'));
}
- // Prevent caching if this is a mutation query.
+ // Prevent caching if this is a mutation query or an error occurs.
$request = $context->getRequest();
- if (!empty($request) && $request->hasMutations()) {
+ if (!empty($request) && $request->hasMutations() || $context->hasErrors()) {
$metadata->setCacheMaxAge(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment