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
|
|
|
/** |
85
|
|
|
* @return OperationDefinitionNode |
86
|
|
|
*/ |
87
|
|
|
public function getOperation(): OperationDefinitionNode |
88
|
|
|
{ |
89
|
|
|
return $this->operation; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return Schema |
94
|
|
|
*/ |
95
|
|
|
public function getSchema(): Schema |
96
|
|
|
{ |
97
|
|
|
return $this->schema; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return array|FragmentDefinitionNode[] |
102
|
|
|
*/ |
103
|
|
|
public function getFragments() |
104
|
|
|
{ |
105
|
|
|
return $this->fragments; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Create proper ExecutionStrategy when needed |
110
|
|
|
* |
111
|
|
|
* @return ExecutionStrategy |
112
|
|
|
*/ |
113
|
|
|
public function getExecutionStrategy(): ExecutionStrategy |
114
|
|
|
{ |
115
|
|
|
//We can probably return different strategy in the future e.g:AsyncExecutionStrategy |
116
|
|
|
return new ExecutorExecutionStrategy($this, $this->operation, $this->rootValue); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param GraphQLError $error |
121
|
|
|
* @return ExecutionContext |
122
|
|
|
*/ |
123
|
|
|
public function addError(GraphQLError $error) |
124
|
|
|
{ |
125
|
|
|
$this->errors[] = $error; |
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return array|GraphQLError[] |
131
|
|
|
*/ |
132
|
|
|
public function getErrors() |
133
|
|
|
{ |
134
|
|
|
return $this->errors; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|