|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql\GraphQL\Execution; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\Cache\RefinableCacheableDependencyInterface; |
|
|
|
|
|
|
6
|
|
|
use Drupal\Core\Cache\RefinableCacheableDependencyTrait; |
|
|
|
|
|
|
7
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
|
8
|
|
|
|
|
9
|
|
|
class ResolveContext implements RefinableCacheableDependencyInterface { |
|
10
|
|
|
use RefinableCacheableDependencyTrait; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Read-only list of global values. |
|
14
|
|
|
* |
|
15
|
|
|
* @var array |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $globals; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The context stack. |
|
21
|
|
|
* |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $contexts = []; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Root context values that will apply if no more specific context is there. |
|
28
|
|
|
* |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $rootContext = []; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* ResolveContext constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param array $globals |
|
37
|
|
|
* List of global values to expose to field resolvers. |
|
38
|
|
|
* @param array $rootContext |
|
39
|
|
|
* The root context values the query will be initialised with. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(array $globals = [], $rootContext = []) { |
|
42
|
|
|
$this->globals = $globals; |
|
43
|
|
|
$this->rootContext = $rootContext; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get a contextual value for the current field. |
|
48
|
|
|
* |
|
49
|
|
|
* Allows field resolvers to inherit contextual values from their ancestors. |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $name |
|
52
|
|
|
* The name of the context. |
|
53
|
|
|
* @param \GraphQL\Type\Definition\ResolveInfo $info |
|
54
|
|
|
* The resolve info object. |
|
55
|
|
|
* @param mixed $default |
|
56
|
|
|
* An arbitrary default value in case the context is not set. |
|
57
|
|
|
* |
|
58
|
|
|
* @return mixed |
|
59
|
|
|
* The current value of the given context or the given default value if the |
|
60
|
|
|
* context wasn't set. |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getContext($name, ResolveInfo $info, $default = NULL) { |
|
63
|
|
|
$operation = isset($info->operation->name->value) ? $info->operation->name->value : $info->operation->operation; |
|
64
|
|
|
$path = $info->path; |
|
65
|
|
|
|
|
66
|
|
|
do { |
|
67
|
|
|
$key = implode('.', $path); |
|
68
|
|
|
if (isset($this->contexts[$operation][$key]) && array_key_exists($name, $this->contexts[$operation][$key])) { |
|
69
|
|
|
return $this->contexts[$operation][$key][$name]; |
|
70
|
|
|
} |
|
71
|
|
|
array_pop($path); |
|
72
|
|
|
} while (count($path)); |
|
73
|
|
|
|
|
74
|
|
|
if (isset($this->rootContext[$name])) { |
|
75
|
|
|
return $this->rootContext[$name]; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $default; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Sets a contextual value for the current field and its decendents. |
|
83
|
|
|
* |
|
84
|
|
|
* Allows field resolvers to set contextual values which can be inherited by |
|
85
|
|
|
* their descendents. |
|
86
|
|
|
* |
|
87
|
|
|
* @param string $name |
|
88
|
|
|
* The name of the context. |
|
89
|
|
|
* @param $value |
|
90
|
|
|
* The value of the context. |
|
91
|
|
|
* @param \GraphQL\Type\Definition\ResolveInfo $info |
|
92
|
|
|
* The resolve info object. |
|
93
|
|
|
* |
|
94
|
|
|
* @return $this |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setContext($name, $value, ResolveInfo $info) { |
|
97
|
|
|
$operation = isset($info->operation->name->value) ? $info->operation->name->value : $info->operation->operation; |
|
98
|
|
|
$key = implode('.', $info->path); |
|
99
|
|
|
$this->contexts[$operation][$key][$name] = $value; |
|
100
|
|
|
|
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Retrieve a global/static parameter value. |
|
106
|
|
|
* |
|
107
|
|
|
* @param string $name |
|
108
|
|
|
* The name of the global parameter. |
|
109
|
|
|
* @param mixed $default |
|
110
|
|
|
* An arbitrary default value in case the context is not set. |
|
111
|
|
|
* |
|
112
|
|
|
* @return mixed|null |
|
113
|
|
|
* The requested global parameter value or the given default value if the |
|
114
|
|
|
* parameter is not set. |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getGlobal($name, $default = NULL) { |
|
117
|
|
|
if (isset($this->globals[$name])) { |
|
118
|
|
|
return $this->globals[$name]; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return $default; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths