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

MutationPluginBase   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 2
c 1
b 1
f 0
lcom 1
cbo 6
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createInstance() 0 9 1
A getDefinition() 0 10 1
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 ($source, $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