MutationPluginManager.php in GraphQL 8.3
File
src/Plugin/MutationPluginManager.php
View source
<?php
namespace Drupal\graphql\Plugin;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
class MutationPluginManager extends DefaultPluginManager {
protected $instances;
public function __construct($pluginSubdirectory, \Traversable $namespaces, ModuleHandlerInterface $moduleHandler, CacheBackendInterface $cacheBackend, $pluginInterface, $pluginAnnotationName, array $config) {
parent::__construct($pluginSubdirectory, $namespaces, $moduleHandler, $pluginInterface, $pluginAnnotationName);
$this
->alterInfo('graphql_mutations');
$this
->useCaches(empty($config['development']));
$this
->setCacheBackend($cacheBackend, 'mutations', [
'graphql',
]);
}
public function getInstance(array $options) {
if (!isset($this->instances[$options['id']])) {
$this->instances[$options['id']] = $this
->createInstance($options['id']);
}
return $this->instances[$options['id']];
}
public function clearCachedDefinitions() {
parent::clearCachedDefinitions();
$this->instances = [];
}
protected function setCachedDefinitions($definitions) {
$this->definitions = $definitions;
$this
->cacheSet($this->cacheKey, $definitions, $this
->getCacheMaxAge(), $this
->getCacheTags());
}
public function getCacheTags() {
$definitions = $this
->getDefinitions();
return array_reduce($definitions, function ($carry, $current) {
if (!empty($current['schema_cache_tags'])) {
return Cache::mergeTags($carry, $current['schema_cache_tags']);
}
return $carry;
}, $this->cacheTags);
}
public function getCacheMaxAge() {
$definitions = $this
->getDefinitions();
$age = Cache::PERMANENT;
foreach ($definitions as $definition) {
if (!isset($definition['schema_cache_max_age'])) {
continue;
}
if (($age = Cache::mergeMaxAges($age, $definition['schema_cache_max_age'])) === 0) {
return $age;
}
}
return $age;
}
}