You are here

abstract class TypePluginBase in GraphQL 8.3

Hierarchy

Expanded class hierarchy of TypePluginBase

22 files declare their use of TypePluginBase
Bike.php in tests/modules/graphql_plugin_test/src/Plugin/GraphQL/Types/Bike.php
Car.php in tests/modules/graphql_plugin_test/src/Plugin/GraphQL/Types/Car.php
ConstraintViolation.php in modules/graphql_core/src/Plugin/GraphQL/Types/Mutations/ConstraintViolation.php
DefaultInternalUrl.php in modules/graphql_core/src/Plugin/GraphQL/Types/Routing/DefaultInternalUrl.php
EntityBundle.php in modules/graphql_core/src/Plugin/GraphQL/Types/Entity/EntityBundle.php

... See full list

1 string reference to 'TypePluginBase'
graphql.services.yml in ./graphql.services.yml
graphql.services.yml

File

src/Plugin/GraphQL/Types/TypePluginBase.php, line 16

Namespace

Drupal\graphql\Plugin\GraphQL\Types
View source
abstract class TypePluginBase extends PluginBase implements TypePluginInterface {
  use CacheablePluginTrait;
  use DescribablePluginTrait;

  /**
   * {@inheritdoc}
   */
  public static function createInstance(SchemaBuilderInterface $builder, TypePluginManager $manager, $definition, $id) {
    return new ObjectType([
      'name' => $definition['name'],
      'description' => $definition['description'],
      'contexts' => $definition['contexts'],
      'fields' => function () use ($builder, $definition) {
        $fields = $builder
          ->getFields($definition['name']);
        if (!empty($definition['interfaces'])) {
          $inherited = array_map(function ($name) use ($builder) {
            return $builder
              ->getFields($name);
          }, $definition['interfaces']);
          $inherited = call_user_func_array('array_merge', $inherited);
          return array_merge($inherited, $fields);
        }
        return $fields;
      },
      'interfaces' => function () use ($builder, $definition) {
        return array_filter(array_map(function ($name) use ($builder) {
          return $builder
            ->getType($name);
        }, $definition['interfaces']), function ($type) {
          return $type instanceof InterfaceType;
        });
      },
      'isTypeOf' => function ($object, $context, ResolveInfo $info) use ($manager, $id) {
        $instance = $manager
          ->getInstance([
          'id' => $id,
        ]);
        return $instance
          ->applies($object, $context, $info);
      },
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getDefinition() {
    $definition = $this
      ->getPluginDefinition();
    return [
      'name' => $definition['name'],
      'description' => $this
        ->buildDescription($definition),
      'interfaces' => $this
        ->buildInterfaces($definition),
      'unions' => $this
        ->buildUnions($definition),
      'contexts' => $this
        ->buildCacheContexts($definition),
      'weight' => $definition['weight'],
    ];
  }

  /**
   * Builds the list of interfaces that this type implements.
   *
   * @param array $definition
   *   The plugin definition array.
   *
   * @return array
   *   The list of interfaces implemented by this type.
   */
  protected function buildInterfaces($definition) {
    return array_unique($definition['interfaces']);
  }

  /**
   * Builds the list of unions that this type belongs to.
   *
   * @param array $definition
   *   The plugin definition array.
   *
   * @return array
   *   The list of unions that this type belongs to.
   */
  protected function buildUnions($definition) {
    return array_unique($definition['unions']);
  }

  /**
   * Checks whether this type applies to a given object.
   *
   * @param mixed $object
   *   The object to check against.
   * @param \Drupal\graphql\GraphQL\Execution\ResolveContext $context
   *   The resolve context.
   * @param \GraphQL\Type\Definition\ResolveInfo $info
   *   The resolve info object.
   *
   * @return null|bool
   *   TRUE if this type applies to the given object or FALSE if it doesn't.
   */
  public function applies($object, ResolveContext $context, ResolveInfo $info) {
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheablePluginTrait::buildCacheContexts protected function
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
TypePluginBase::applies public function Checks whether this type applies to a given object. 9
TypePluginBase::buildInterfaces protected function Builds the list of interfaces that this type implements.
TypePluginBase::buildUnions protected function Builds the list of unions that this type belongs to.
TypePluginBase::createInstance public static function Overrides TypePluginInterface::createInstance
TypePluginBase::getDefinition public function Returns the plugin's type or field definition for the schema. Overrides TypePluginInterface::getDefinition