SdlSchemaExtensionPluginBase.php in GraphQL 8.4
File
src/Plugin/GraphQL/SchemaExtension/SdlSchemaExtensionPluginBase.php
View source
<?php
namespace Drupal\graphql\Plugin\GraphQL\SchemaExtension;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\graphql\Plugin\SchemaExtensionPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class SdlSchemaExtensionPluginBase extends PluginBase implements SchemaExtensionPluginInterface, ContainerFactoryPluginInterface {
protected $moduleHandler;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('module_handler'));
}
public function __construct(array $configuration, $pluginId, array $pluginDefinition, ModuleHandlerInterface $moduleHandler) {
parent::__construct($configuration, $pluginId, $pluginDefinition);
$this->moduleHandler = $moduleHandler;
}
public function getBaseDefinition() {
return $this
->loadDefinitionFile('base');
}
public function getExtensionDefinition() {
return $this
->loadDefinitionFile('extension');
}
protected function loadDefinitionFile($type) {
$id = $this
->getPluginId();
$definition = $this
->getPluginDefinition();
$module = $this->moduleHandler
->getModule($definition['provider']);
$path = 'graphql/' . $id . '.' . $type . '.graphqls';
$file = $module
->getPath() . '/' . $path;
if (!file_exists($file)) {
throw new InvalidPluginDefinitionException($id, sprintf('The module "%s" needs to have a schema definition "%s" in its folder for "%s" to be valid.', $module
->getName(), $path, $definition['class']));
}
return file_get_contents($file) ?: NULL;
}
}