You are here

protected function SdlSchemaPluginBase::getExtensionDocument in GraphQL 8.4

Retrieves the parsed AST of the schema extension definitions.

Parameters

array $extensions:

Return value

\GraphQL\Language\AST\DocumentNode|null The parsed schema document.

Throws

\GraphQL\Error\SyntaxError

1 call to SdlSchemaPluginBase::getExtensionDocument()
SdlSchemaPluginBase::getSchema in src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php

File

src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php, line 195

Class

SdlSchemaPluginBase
Base class that can be used by schema plugins.

Namespace

Drupal\graphql\Plugin\GraphQL\Schema

Code

protected function getExtensionDocument(array $extensions = []) {

  // Only use caching of the parsed document if we aren't in development mode.
  $cid = "extension:{$this->getPluginId()}";
  if (empty($this->inDevelopment) && ($cache = $this->astCache
    ->get($cid))) {
    return $cache->data;
  }
  $extensions = array_filter(array_map(function (SchemaExtensionPluginInterface $extension) {
    return $extension
      ->getExtensionDefinition();
  }, $extensions), function ($definition) {
    return !empty($definition);
  });
  $ast = !empty($extensions) ? Parser::parse(implode("\n\n", $extensions)) : NULL;
  if (empty($this->inDevelopment)) {
    $this->astCache
      ->set($cid, $ast, CacheBackendInterface::CACHE_PERMANENT, [
      'graphql',
    ]);
  }
  return $ast;
}