You are here

class ComposableSchema in GraphQL 8.4

Plugin annotation


@Schema(
  id = "composable",
  name = "Composable schema"
)

Hierarchy

Expanded class hierarchy of ComposableSchema

1 file declares its use of ComposableSchema
ComposableSchemaExample.php in examples/graphql_composable/src/Plugin/GraphQL/Schema/ComposableSchemaExample.php

File

src/Plugin/GraphQL/Schema/ComposableSchema.php, line 18

Namespace

Drupal\graphql\Plugin\GraphQL\Schema
View source
class ComposableSchema extends SdlSchemaPluginBase implements ConfigurableInterface, PluginFormInterface {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function getResolverRegistry() {
    return new ResolverRegistry();
  }

  /**
   * {@inheritdoc}
   */
  protected function getExtensions() {
    return array_map(function ($id) {
      return $this->extensionManager
        ->createInstance($id);
    }, array_filter($this
      ->getConfiguration()['extensions']));
  }

  /**
   * {@inheritdoc}
   */
  protected function getSchemaDefinition() {
    return <<<GQL
      type Schema {
        query: Query
      }

      type Query
GQL;
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return $this->configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) : void {
    $this->configuration = NestedArray::mergeDeep($this
      ->defaultConfiguration(), $configuration);
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $extensions = $this->extensionManager
      ->getDefinitions();
    $form['extensions'] = [
      '#type' => 'checkboxes',
      '#required' => FALSE,
      '#title' => $this
        ->t('Enabled extensions'),
      '#options' => [],
      '#default_value' => $this->configuration['extensions'] ?? [],
    ];
    foreach ($extensions as $key => $extension) {
      $form['extensions']['#options'][$key] = $extension['name'] ?? $extension['id'];
      if (!empty($extension['description'])) {
        $form['extensions'][$key]['#description'] = $extension['description'];
      }
    }
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $formState) : void {

    // @todo Validate dependencies between extensions.
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $formState) : void {

    // Nothing to do here.
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::getCacheContexts public function 3
CacheableDependencyTrait::getCacheMaxAge public function 3
CacheableDependencyTrait::getCacheTags public function 3
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
ComposableSchema::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
ComposableSchema::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration
ComposableSchema::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
ComposableSchema::getExtensions protected function Overrides SdlSchemaPluginBase::getExtensions
ComposableSchema::getResolverRegistry public function Retrieves the resolver registry. Overrides SchemaPluginInterface::getResolverRegistry
ComposableSchema::getSchemaDefinition protected function Retrieves the raw schema definition string. Overrides SdlSchemaPluginBase::getSchemaDefinition
ComposableSchema::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
ComposableSchema::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
ComposableSchema::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
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.
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function
SdlSchemaPluginBase::$astCache protected property The cache bin for caching the parsed SDL.
SdlSchemaPluginBase::$extensionManager protected property The schema extension plugin manager.
SdlSchemaPluginBase::$inDevelopment protected property Whether the system is currently in development mode.
SdlSchemaPluginBase::$moduleHandler protected property The module handler service.
SdlSchemaPluginBase::create public static function @codeCoverageIgnore Overrides ContainerFactoryPluginInterface::create
SdlSchemaPluginBase::getExtensionDocument protected function Retrieves the parsed AST of the schema extension definitions.
SdlSchemaPluginBase::getSchema public function Overrides SchemaPluginInterface::getSchema
SdlSchemaPluginBase::getSchemaDocument protected function Retrieves the parsed AST of the schema definition.
SdlSchemaPluginBase::__construct public function SdlSchemaPluginBase 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.