Completed
Pull Request — 8.x-3.x (#525)
by Sebastian
02:27
created

MutationPluginBase::getDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql\Plugin\GraphQL\Mutations;
4
5
use Drupal\Component\Plugin\PluginBase;
6
use Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilder;
7
use Drupal\graphql\Plugin\GraphQL\Traits\ArgumentAwarePluginTrait;
8
use Drupal\graphql\Plugin\GraphQL\Traits\CacheablePluginTrait;
9
use Drupal\graphql\Plugin\GraphQL\Traits\DeprecatablePluginTrait;
10
use Drupal\graphql\Plugin\GraphQL\Traits\DescribablePluginTrait;
11
use Drupal\graphql\Plugin\GraphQL\Traits\TypedPluginTrait;
12
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginInterface;
13
14
/**
15
 * Base class for graphql mutation plugins.
16
 */
17
abstract class MutationPluginBase extends PluginBase implements TypeSystemPluginInterface {
18
  use CacheablePluginTrait;
19
  use TypedPluginTrait;
20
  use DescribablePluginTrait;
21
  use ArgumentAwarePluginTrait;
22
  use DeprecatablePluginTrait;
23
24
  /**
25
   * {@inheritdoc}
26
   */
27
  public static function createInstance(PluggableSchemaBuilder $builder, $definition, $id) {
28
    return [
29
      'args' => $builder->resolveArgs($definition['args']),
30
      'resolve' => function ($args) use ($builder, $id) {
31
        $instance = $builder->getPluginInstance(GRAPHQL_MUTATION_PLUGIN, $id);
32
        return call_user_func_array([$instance, 'resolve'], $args);
33
      },
34
    ] + $definition;
35
  }
36
37
  /**
38
   * {@inheritdoc}
39
   */
40
  public function getDefinition() {
41
    $definition = $this->getPluginDefinition();
42
43
    return [
44
      'type' => $this->buildType($definition),
45
      'description' => $this->buildDescription($definition),
46
      'args' => $this->buildArguments($definition),
47
      'deprecationReason' => $this->buildDeprecationReason($definition)
48
    ];
49
  }
50
51
}
52