You are here

abstract class SdlSchemaExtensionPluginBase in GraphQL 8.4

Base class that can be used for schema extension plugins.

Hierarchy

Expanded class hierarchy of SdlSchemaExtensionPluginBase

2 files declare their use of SdlSchemaExtensionPluginBase
ComposableSchemaExampleExtension.php in examples/graphql_composable/src/Plugin/GraphQL/SchemaExtension/ComposableSchemaExampleExtension.php
ExampleSchemaExtension.php in examples/graphql_example/src/Plugin/GraphQL/SchemaExtension/ExampleSchemaExtension.php

File

src/Plugin/GraphQL/SchemaExtension/SdlSchemaExtensionPluginBase.php, line 15

Namespace

Drupal\graphql\Plugin\GraphQL\SchemaExtension
View source
abstract class SdlSchemaExtensionPluginBase extends PluginBase implements SchemaExtensionPluginInterface, ContainerFactoryPluginInterface {

  /**
   * The module handler service.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * {@inheritdoc}
   *
   * @codeCoverageIgnore
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('module_handler'));
  }

  /**
   * SdlSchemaExtensionPluginBase constructor.
   *
   * @param array $configuration
   *   The plugin configuration array.
   * @param string $pluginId
   *   The plugin id.
   * @param array $pluginDefinition
   *   The plugin definition array.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
   *   The module handler service.
   *
   * @codeCoverageIgnore
   */
  public function __construct(array $configuration, $pluginId, array $pluginDefinition, ModuleHandlerInterface $moduleHandler) {
    parent::__construct($configuration, $pluginId, $pluginDefinition);
    $this->moduleHandler = $moduleHandler;
  }

  /**
   * {@inheritdoc}
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   */
  public function getBaseDefinition() {
    return $this
      ->loadDefinitionFile('base');
  }

  /**
   * {@inheritdoc}
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   */
  public function getExtensionDefinition() {
    return $this
      ->loadDefinitionFile('extension');
  }

  /**
   * Loads a schema definition file.
   *
   * @param string $type
   *   The type of the definition file to load.
   *
   * @return string|null
   *   The loaded definition file content or NULL if it was empty.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SchemaExtensionPluginInterface::registerResolvers public function Registers type and field resolvers in the shared registry. 2
SdlSchemaExtensionPluginBase::$moduleHandler protected property The module handler service.
SdlSchemaExtensionPluginBase::create public static function @codeCoverageIgnore Overrides ContainerFactoryPluginInterface::create
SdlSchemaExtensionPluginBase::getBaseDefinition public function Overrides SchemaExtensionPluginInterface::getBaseDefinition
SdlSchemaExtensionPluginBase::getExtensionDefinition public function Overrides SchemaExtensionPluginInterface::getExtensionDefinition
SdlSchemaExtensionPluginBase::loadDefinitionFile protected function Loads a schema definition file.
SdlSchemaExtensionPluginBase::__construct public function SdlSchemaExtensionPluginBase constructor. Overrides PluginBase::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.