diff --git a/src/Plugin/GraphQL/Schema/SdlExtendedSchemaPluginBase.php b/src/Plugin/GraphQL/Schema/SdlExtendedSchemaPluginBase.php new file mode 100644 index 000000000..7ce557d36 --- /dev/null +++ b/src/Plugin/GraphQL/Schema/SdlExtendedSchemaPluginBase.php @@ -0,0 +1,54 @@ +inDevelopment) && $cache = $this->astCache->get($this->getPluginId())) { + return $cache->data; + } + + $ast = Parser::parse($this->getExtendedSchemaDefinition()); + if (!empty($this->inDevelopment)) { + $this->astCache->set($this->getPluginId(), $ast, CacheBackendInterface::CACHE_PERMANENT, ['graphql']); + } + + return $ast; + } + + /** + * {@inheritdoc} + */ + public function getSchema() { + return SchemaExtender::extend(parent::getSchema(), $this->getExtendedSchemaDocument()); + } + + /** + * Retrieves the raw extended schema definition string. + * + * @return string + * The extended schema definition. + */ + abstract protected function getExtendedSchemaDefinition(); + +} diff --git a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php index 24d01cf31..ebd851e53 100644 --- a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php +++ b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php @@ -189,7 +189,7 @@ protected function getTypeResolver(TypeDefinitionNode $type) { * The parsed schema document. */ protected function getSchemaDocument() { - // Only use caching of the parsed document if aren't in development mode. + // Only use caching of the parsed document if we aren't in development mode. if (empty($this->inDevelopment) && $cache = $this->astCache->get($this->getPluginId())) { return $cache->data; }