Completed
Push — 8.x-3.x ( e67c0e...2e01b0 )
by Philipp
02:27
created

MutationPluginBase::getDefinition()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 2
nop 1
dl 0
loc 16
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\GraphQL\Field\Field;
7
use Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface;
8
use Drupal\graphql\Plugin\GraphQL\Traits\ArgumentAwarePluginTrait;
9
use Drupal\graphql\Plugin\GraphQL\Traits\CacheablePluginTrait;
10
use Drupal\graphql\Plugin\GraphQL\Traits\NamedPluginTrait;
11
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginInterface;
12
13
/**
14
 * Base class for graphql mutation plugins.
15
 */
16
abstract class MutationPluginBase extends PluginBase implements TypeSystemPluginInterface {
17
  use CacheablePluginTrait;
18
  use NamedPluginTrait;
19
  use ArgumentAwarePluginTrait;
20
21
  /**
22
   * The field instance.
23
   *
24
   * @var \Drupal\graphql\GraphQL\Field\Field
25
   */
26
  protected $definition;
27
28
  /**
29
   * {@inheritdoc}
30
   */
31
  public function getDefinition(PluggableSchemaBuilderInterface $schemaBuilder) {
32
    if (!isset($this->definition)) {
33
      $definition = $this->getPluginDefinition();
34
35
      $this->definition = new Field($this, TRUE, [
36
        'name' => $this->buildName(),
37
        'description' => $this->buildDescription(),
38
        'type' => $this->buildType($schemaBuilder),
39
        'args' => $this->buildArguments($schemaBuilder),
40
        'isDeprecated' => !empty($definition['deprecated']),
41
        'deprecationReason' => !empty($definition['deprecated']) ? !empty($definition['deprecated']) : '',
42
      ]);
43
    }
44
45
    return $this->definition;
46
  }
47
48
}
49