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

Field   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A resolve() 0 7 3
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\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
   * The associated type system plugin.
22
   *
23
   * @var \Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase|\Drupal\graphql\Plugin\GraphQL\Mutations\MutationPluginBase
24
   */
25
  protected $plugin;
26
27
  /**
28
   * Indicates if the field is considered secure.
29
   *
30
   * @var bool
31
   */
32
  protected $secure;
33
34
  /**
35
   * {@inheritdoc}
36
   */
37
  public function __construct(TypeSystemPluginInterface $plugin, $secure, array $config = []) {
38
    $this->plugin = $plugin;
39
    $this->secure = $secure;
40
    $this->config = new FieldConfig($config, $this, TRUE);
41
  }
42
43
  /**
44
   * {@inheritdoc}
45
   */
46
  public function resolve($value, array $args, ResolveInfo $info) {
47
    if (($plugin = $this->getPluginFromResolveInfo($info)) && $plugin instanceof FieldPluginBase) {
48
      return $plugin->resolve($value, $args, $info);
49
    }
50
51
    return NULL;
52
  }
53
54
  /**
55
   * {@inheritdoc}
56
   */
57
  public function getType() {
58
    return $this->getConfigValue('type');
59
  }
60
61
  /**
62
   * {@inheritdoc}
63
   */
64
  public function getName() {
65
    return $this->getConfigValue('name');
66
  }
67
68
  /**
69
   * {@inheritdoc}
70
   */
71
  public function isSecure() {
72
    return $this->secure;
73
  }
74
}
75