1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Arthem\GraphQLMapper\Mapping; |
4
|
|
|
|
5
|
|
|
use GraphQL\Type\Definition\Type as GQLType; |
6
|
|
|
|
7
|
|
|
class Field extends AbstractType |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* The model field name |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
private $field; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $type; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var GQLType |
23
|
|
|
*/ |
24
|
|
|
private $resolvedType; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var callable |
28
|
|
|
*/ |
29
|
|
|
private $resolve; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
private $resolveConfig = []; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Field[] |
38
|
|
|
*/ |
39
|
|
|
private $arguments = []; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public function getField() |
45
|
|
|
{ |
46
|
|
|
return $this->field; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $field |
51
|
|
|
* @return $this |
52
|
|
|
*/ |
53
|
|
|
public function setField($field) |
54
|
|
|
{ |
55
|
|
|
$this->field = $field; |
56
|
|
|
|
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getType() |
64
|
|
|
{ |
65
|
|
|
return $this->type; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $type |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function setType($type) |
73
|
|
|
{ |
74
|
|
|
$this->type = $type; |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return callable|GQLType |
81
|
|
|
*/ |
82
|
|
|
public function getResolvedType() |
83
|
|
|
{ |
84
|
|
|
return $this->resolvedType; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param callable|GQLType $resolvedType |
89
|
|
|
* @return $this |
90
|
|
|
*/ |
91
|
|
|
public function setResolvedType($resolvedType) |
92
|
|
|
{ |
93
|
|
|
$this->resolvedType = $resolvedType; |
|
|
|
|
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return callable |
100
|
|
|
*/ |
101
|
|
|
public function getResolve() |
102
|
|
|
{ |
103
|
|
|
return $this->resolve; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param callable $resolve |
108
|
|
|
* @return $this |
109
|
|
|
*/ |
110
|
|
|
public function setResolve($resolve) |
111
|
|
|
{ |
112
|
|
|
$this->resolve = $resolve; |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return array |
119
|
|
|
*/ |
120
|
|
|
public function getResolveConfig() |
121
|
|
|
{ |
122
|
|
|
return $this->resolveConfig; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param array $resolveConfig |
127
|
|
|
* @return $this |
128
|
|
|
*/ |
129
|
|
|
public function setResolveConfig($resolveConfig) |
130
|
|
|
{ |
131
|
|
|
$this->resolveConfig = $resolveConfig; |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param array $config |
138
|
|
|
* @return $this |
139
|
|
|
*/ |
140
|
|
|
public function mergeRevolveConfig(array $config) |
141
|
|
|
{ |
142
|
|
|
$this->resolveConfig = array_merge($this->resolveConfig, $config); |
143
|
|
|
|
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return Field[] |
149
|
|
|
*/ |
150
|
|
|
public function getArguments() |
151
|
|
|
{ |
152
|
|
|
return $this->arguments; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param Field[] $arguments |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
|
|
public function setArguments(array $arguments) |
160
|
|
|
{ |
161
|
|
|
$this->arguments = $arguments; |
162
|
|
|
|
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return array |
168
|
|
|
*/ |
169
|
|
|
public function toMapping() |
170
|
|
|
{ |
171
|
|
|
$mapping = [ |
172
|
|
|
'type' => $this->resolvedType, |
173
|
|
|
'resolve' => $this->resolve, |
174
|
|
|
'resolve_config' => $this->resolveConfig, |
175
|
|
|
] + parent::toMapping(); |
176
|
|
|
|
177
|
|
|
if (!empty($this->arguments)) { |
178
|
|
|
$mapping['args'] = []; |
179
|
|
|
foreach ($this->arguments as $argument) { |
180
|
|
|
$mapping['args'][$argument->getName()] = $argument->toMapping(); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
return $mapping; |
|
|
|
|
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..