Completed
Pull Request — 8.x-3.x (#525)
by Philipp
02:10
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
abstract class MutationPluginBase extends PluginBase implements TypeSystemPluginInterface {
15
  use CacheablePluginTrait;
16
  use TypedPluginTrait;
17
  use DescribablePluginTrait;
18
  use ArgumentAwarePluginTrait;
19
  use DeprecatablePluginTrait;
20
21
  /**
22
   * {@inheritdoc}
23
   */
24
  public static function createInstance(PluggableSchemaBuilder $builder, $definition, $id) {
25
    return [
26
      'args' => $builder->resolveArgs($definition['args']),
27
      'resolve' => function ($args) use ($builder, $id) {
28
        $instance = $builder->getPluginInstance(GRAPHQL_MUTATION_PLUGIN, $id);
29
        return call_user_func_array([$instance, 'resolve'], $args);
30
      },
31
    ] + $definition;
32
  }
33
34
  /**
35
   * {@inheritdoc}
36
   */
37
  public function getDefinition() {
38
    $definition = $this->getPluginDefinition();
39
40
    return [
41
      'type' => $this->buildType($definition),
42
      'description' => $this->buildDescription($definition),
43
      'args' => $this->buildArguments($definition),
44
      'deprecationReason' => $this->buildDeprecationReason($definition)
45
    ];
46
  }
47
48
}
49