From ca6abd9cd65d5c85ab4872d617ebccef72bcaa11 Mon Sep 17 00:00:00 2001 From: maxpogonowski Date: Wed, 8 Jun 2022 13:23:10 +1000 Subject: [PATCH 1/2] don't cache unserializable ast graph --- .../GraphQL/Schema/SdlSchemaPluginBase.php | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php index 47d1e7f2c..c55d3f3ea 100644 --- a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php +++ b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php @@ -164,22 +164,21 @@ protected function getSchemaDocument(array $extensions = []) { // Only use caching of the parsed document if we aren't in development mode. $cid = "schema:{$this->getPluginId()}"; if (empty($this->inDevelopment) && $cache = $this->astCache->get($cid)) { - return $cache->data; - } - - $extensions = array_filter(array_map(function (SchemaExtensionPluginInterface $extension) { - return $extension->getBaseDefinition(); - }, $extensions), function ($definition) { - return !empty($definition); - }); - - $schema = array_merge([$this->getSchemaDefinition()], $extensions); - $ast = Parser::parse(implode("\n\n", $schema)); - if (empty($this->inDevelopment)) { - $this->astCache->set($cid, $ast, CacheBackendInterface::CACHE_PERMANENT, ['graphql']); + $schema = $cache->data; + } else { + $extensions = array_filter(array_map(function (SchemaExtensionPluginInterface $extension) { + return $extension->getBaseDefinition(); + }, $extensions), function ($definition) { + return !empty($definition); + }); + + $schema = array_merge([$this->getSchemaDefinition()], $extensions); + if (empty($this->inDevelopment)) { + $this->astCache->set($cid, $schema, CacheBackendInterface::CACHE_PERMANENT, ['graphql']); + } } - return $ast; + return Parser::parse(implode("\n\n", $schema)); } /** From 7887eb031c862e2b90371d1953d9aaf6b9edab84 Mon Sep 17 00:00:00 2001 From: maxpogonowski Date: Wed, 8 Jun 2022 13:31:51 +1000 Subject: [PATCH 2/2] newline after closing brace --- src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php index c55d3f3ea..5637a6bf4 100644 --- a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php +++ b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php @@ -165,7 +165,8 @@ protected function getSchemaDocument(array $extensions = []) { $cid = "schema:{$this->getPluginId()}"; if (empty($this->inDevelopment) && $cache = $this->astCache->get($cid)) { $schema = $cache->data; - } else { + } + else { $extensions = array_filter(array_map(function (SchemaExtensionPluginInterface $extension) { return $extension->getBaseDefinition(); }, $extensions), function ($definition) {