You are here

abstract class UnionTypePluginBase in GraphQL 8.3

Hierarchy

Expanded class hierarchy of UnionTypePluginBase

1 file declares its use of UnionTypePluginBase
MockGraphQLPluginTrait.php in tests/src/Traits/MockGraphQLPluginTrait.php
1 string reference to 'UnionTypePluginBase'
graphql.services.yml in ./graphql.services.yml
graphql.services.yml

File

src/Plugin/GraphQL/Unions/UnionTypePluginBase.php, line 13

Namespace

Drupal\graphql\Plugin\GraphQL\Unions
View source
abstract class UnionTypePluginBase extends PluginBase implements TypePluginInterface {
  use DescribablePluginTrait;

  /**
   * {@inheritdoc}
   */
  public static function createInstance(SchemaBuilderInterface $builder, TypePluginManager $manager, $definition, $id) {
    return new UnionType([
      'name' => $definition['name'],
      'description' => $definition['description'],
      'types' => function () use ($builder, $definition) {
        return array_map(function ($type) use ($builder) {
          if (!($type = $builder
            ->getType($type)) instanceof ObjectType) {
            throw new \LogicException('Union types can only reference object types.');
          }
          return $type;
        }, $builder
          ->getSubTypes($definition['name']));
      },
      'resolveType' => function ($value, $context, $info) use ($builder, $definition) {
        return $builder
          ->resolveType($definition['name'], $value, $context, $info);
      },
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getDefinition() {
    $definition = $this
      ->getPluginDefinition();
    return [
      'name' => $definition['name'],
      'description' => $this
        ->buildDescription($definition),
      'types' => $this
        ->buildTypes($definition),
    ];
  }

  /**
   * Builds the list of types contained within this union type.
   *
   * @param array $definition
   *   The plugin definion array.
   *
   * @return array
   *   The list of types contained within this union type.
   */
  protected function buildTypes($definition) {
    return $definition['types'] ?: [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DescribablePluginTrait::buildDescription protected function
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.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
UnionTypePluginBase::buildTypes protected function Builds the list of types contained within this union type.
UnionTypePluginBase::createInstance public static function Overrides TypePluginInterface::createInstance
UnionTypePluginBase::getDefinition public function Returns the plugin's type or field definition for the schema. Overrides TypePluginInterface::getDefinition