class SchemaLoader in GraphQL 8.2
Same name and namespace in other branches
- 8 src/SchemaLoader.php \Drupal\graphql\SchemaLoader
Loads and caches a generated GraphQL schema.
Hierarchy
- class \Drupal\graphql\SchemaLoader
Expanded class hierarchy of SchemaLoader
1 file declares its use of SchemaLoader
- RequestController.php in src/
Controller/ RequestController.php
1 string reference to 'SchemaLoader'
1 service uses SchemaLoader
File
- src/
SchemaLoader.php, line 14
Namespace
Drupal\graphqlView source
class SchemaLoader {
/**
* The schema provider service.
*
* @var \Drupal\graphql\SchemaProviderInterface
*/
protected $schemaProvider;
/**
* The schema cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $schemaCache;
/**
* Constructs a SchemaLoader object.
*
* @param \Drupal\graphql\SchemaProviderInterface $schema_provider
* The schema provider service.
* @param \Drupal\Core\Cache\CacheBackendInterface $schema_cache
* The schema cache backend.
*/
public function __construct(SchemaProviderInterface $schema_provider, CacheBackendInterface $schema_cache) {
$this->schemaProvider = $schema_provider;
$this->schemaCache = $schema_cache;
}
/**
* Loads and caches the generated schema.
*
* @param \Drupal\Core\Language\LanguageInterface $language
* The language for which to fetch the schema.
*
* @return \Fubhy\GraphQL\Schema The generated GraphQL schema.
* The generated GraphQL schema.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SchemaLoader:: |
protected | property | The schema cache backend. | |
SchemaLoader:: |
protected | property | The schema provider service. | |
SchemaLoader:: |
public | function | Loads and caches the generated schema. | |
SchemaLoader:: |
public | function | Constructs a SchemaLoader object. |