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

Field   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

5 Methods

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