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

Field   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A resolve() 0 7 4
A getType() 0 3 1
A getName() 0 3 1
A isSecure() 0 3 1
1
<?php
2
3
namespace Drupal\graphql\GraphQL\Field;
4
5
use Drupal\graphql\GraphQL\CacheableEdgeInterface;
6
use Drupal\graphql\GraphQL\CacheableEdgeTrait;
7
use Drupal\graphql\GraphQL\SecureFieldInterface;
8
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
9
use Drupal\graphql\Plugin\GraphQL\Mutations\MutationPluginBase;
10
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginInterface;
11
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginReferenceInterface;
12
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginReferenceTrait;
13
use Youshido\GraphQL\Config\Field\FieldConfig;
14
use Youshido\GraphQL\Execution\ResolveInfo;
15
use Youshido\GraphQL\Field\AbstractField;
16
17
class Field extends AbstractField implements SecureFieldInterface, TypeSystemPluginReferenceInterface, CacheableEdgeInterface {
18
  use TypeSystemPluginReferenceTrait;
19
  use CacheableEdgeTrait;
20
21
  /**
22
   * Indicates if the field is considered secure.
23
   *
24
   * @var bool
25
   */
26
  protected $secure;
27
28
  /**
29
   * {@inheritdoc}
30
   */
31
  public function __construct(TypeSystemPluginInterface $plugin, $secure, array $config = []) {
32
    $this->plugin = $plugin;
33
    $this->secure = $secure;
34
    $this->config = new FieldConfig($config, $this, TRUE);
35
  }
36
37
  /**
38
   * {@inheritdoc}
39
   */
40
  public function resolve($value, array $args, ResolveInfo $info) {
41
    if (($plugin = $this->getPluginFromResolveInfo($info)) && ($plugin instanceof FieldPluginBase || $plugin instanceof MutationPluginBase)) {
42
      return $plugin->resolve($value, $args, $info);
43
    }
44
45
    return NULL;
46
  }
47
48
  /**
49
   * {@inheritdoc}
50
   */
51
  public function getType() {
52
    return $this->getConfigValue('type');
53
  }
54
55
  /**
56
   * {@inheritdoc}
57
   */
58
  public function getName() {
59
    return $this->getConfigValue('name');
60
  }
61
62
  /**
63
   * {@inheritdoc}
64
   */
65
  public function isSecure() {
66
    return $this->secure;
67
  }
68
}
69