|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Digia\GraphQL\Execution; |
|
4
|
|
|
|
|
5
|
|
|
use Digia\GraphQL\Error\GraphQLError; |
|
6
|
|
|
use Digia\GraphQL\Language\AST\Node\FragmentDefinitionNode; |
|
7
|
|
|
use Digia\GraphQL\Language\AST\Node\OperationDefinitionNode; |
|
8
|
|
|
use Digia\GraphQL\Type\Schema; |
|
9
|
|
|
|
|
10
|
|
|
class ExecutionContext |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var Schema |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $schema; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var FragmentDefinitionNode[] |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $fragments; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var mixed |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $rootValue; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var mixed |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $contextValue; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var [] |
|
34
|
|
|
*/ |
|
|
|
|
|
|
35
|
|
|
protected $variableValues; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var mixed |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $fieldResolver; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var OperationDefinitionNode |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $operation; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var GraphQLError[] |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $errors; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* ExecutionContext constructor. |
|
54
|
|
|
* @param Schema $schema |
|
55
|
|
|
* @param array $fragments |
|
56
|
|
|
* @param $rootValue |
|
57
|
|
|
* @param $contextValue |
|
58
|
|
|
* @param $variableValues |
|
59
|
|
|
* @param $fieldResolver |
|
60
|
|
|
* @param OperationDefinitionNode $operatgion |
|
61
|
|
|
* @param array $errors |
|
62
|
|
|
*/ |
|
63
|
|
|
public function __construct( |
|
64
|
|
|
Schema $schema, |
|
65
|
|
|
array $fragments, |
|
66
|
|
|
$rootValue, |
|
67
|
|
|
$contextValue, |
|
68
|
|
|
$variableValues, |
|
69
|
|
|
$fieldResolver, |
|
70
|
|
|
OperationDefinitionNode $operation, |
|
71
|
|
|
array $errors |
|
72
|
|
|
) { |
|
73
|
|
|
$this->schema = $schema; |
|
74
|
|
|
$this->fragments = $fragments; |
|
75
|
|
|
$this->rootValue = $rootValue; |
|
76
|
|
|
$this->contextValue = $contextValue; |
|
77
|
|
|
$this->variableValues = $variableValues; |
|
78
|
|
|
$this->fieldResolver = $fieldResolver; |
|
79
|
|
|
$this->operation = $operation; |
|
80
|
|
|
$this->errors = $errors; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return mixed |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getRootValue() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->rootValue; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param mixed $rootValue |
|
93
|
|
|
* @return ExecutionContext |
|
94
|
|
|
*/ |
|
95
|
|
|
public function setRootValue($rootValue) |
|
96
|
|
|
{ |
|
97
|
|
|
$this->rootValue = $rootValue; |
|
98
|
|
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return mixed |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getContextValue() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->contextValue; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param mixed $contextValue |
|
111
|
|
|
* @return ExecutionContext |
|
112
|
|
|
*/ |
|
113
|
|
|
public function setContextValue($contextValue) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->contextValue = $contextValue; |
|
116
|
|
|
return $this; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return mixed |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getVariableValues() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->variableValues; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @param mixed $variableValues |
|
129
|
|
|
* @return ExecutionContext |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setVariableValues($variableValues) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->variableValues = $variableValues; |
|
134
|
|
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return mixed |
|
139
|
|
|
*/ |
|
140
|
|
|
public function getFieldResolver() |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->fieldResolver; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @param mixed $fieldResolver |
|
147
|
|
|
* @return ExecutionContext |
|
148
|
|
|
*/ |
|
149
|
|
|
public function setFieldResolver($fieldResolver) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->fieldResolver = $fieldResolver; |
|
152
|
|
|
return $this; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return OperationDefinitionNode |
|
158
|
|
|
*/ |
|
159
|
|
|
public function getOperation(): OperationDefinitionNode |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->operation; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @return Schema |
|
166
|
|
|
*/ |
|
167
|
|
|
public function getSchema(): Schema |
|
168
|
|
|
{ |
|
169
|
|
|
return $this->schema; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @return array|FragmentDefinitionNode[] |
|
174
|
|
|
*/ |
|
175
|
|
|
public function getFragments() |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->fragments; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Create proper ExecutionStrategy when needed |
|
182
|
|
|
* |
|
183
|
|
|
* @return ExecutionStrategy |
|
184
|
|
|
*/ |
|
185
|
|
|
public function getExecutionStrategy(): ExecutionStrategy |
|
186
|
|
|
{ |
|
187
|
|
|
//We can probably return different strategy in the future e.g:AsyncExecutionStrategy |
|
188
|
|
|
return new ExecutorExecutionStrategy($this, $this->operation, $this->rootValue); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @param GraphQLError $error |
|
193
|
|
|
* @return ExecutionContext |
|
194
|
|
|
*/ |
|
195
|
|
|
public function addError(GraphQLError $error) |
|
196
|
|
|
{ |
|
197
|
|
|
$this->errors[] = $error; |
|
198
|
|
|
return $this; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* @return array|GraphQLError[] |
|
203
|
|
|
*/ |
|
204
|
|
|
public function getErrors() |
|
205
|
|
|
{ |
|
206
|
|
|
return $this->errors; |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
|