|
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
|
|
|
|