You are here

public function SchemaLoader::loadSchema in GraphQL 8.2

Same name and namespace in other branches
  1. 8 src/SchemaLoader.php \Drupal\graphql\SchemaLoader::loadSchema()

Loads and caches the generated schema.

Parameters

\Drupal\Core\Language\LanguageInterface $language: The language for which to fetch the schema.

Return value

\Fubhy\GraphQL\Schema The generated GraphQL schema. The generated GraphQL schema.

File

src/SchemaLoader.php, line 51

Class

SchemaLoader
Loads and caches a generated GraphQL schema.

Namespace

Drupal\graphql

Code

public function loadSchema(LanguageInterface $language) {
  if ($schema = $this->schemaCache
    ->get($language
    ->getId())) {

    //return $schema->data;
  }
  $query = new ObjectType('Root', $this->schemaProvider
    ->getQuerySchema());
  $mutation = $this->schemaProvider
    ->getMutationSchema();
  $mutation = $mutation ? new ObjectType('Mutation', $mutation) : NULL;
  $schema = new Schema($query, $mutation);

  // Resolve the type map to get rid of any closures before serialization.
  $schema
    ->getTypeMap();

  // Cache the generated schema in the configured cache backend.
  $expire = Cache::PERMANENT;
  $tags = [
    'views',
    'entity_field_info',
    'entity_bundles',
  ];
  $cid = $language
    ->getId();
  $this->schemaCache
    ->set($cid, $schema, $expire, $tags);
  return $schema;
}