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

Field::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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