You are here

protected function SdlSchemaPluginBase::getSchemaDocument in GraphQL 8.4

Retrieves the parsed AST of the schema definition.

Parameters

array $extensions:

Return value

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

Throws

\GraphQL\Error\SyntaxError

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

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

File

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

Class

SdlSchemaPluginBase
Base class that can be used by schema plugins.

Namespace

Drupal\graphql\Plugin\GraphQL\Schema

Code

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',
    ]);
  }
  return $ast;
}