1 | <?php |
||
15 | class GraphQLField implements GraphQLFieldInterface |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @var string $name |
||
20 | */ |
||
21 | protected $name; |
||
22 | |||
23 | /** |
||
24 | * @var string|string[] $type |
||
25 | */ |
||
26 | protected $type; |
||
27 | |||
28 | /** |
||
29 | * @var string|null $key |
||
30 | */ |
||
31 | protected $key; |
||
32 | |||
33 | /** |
||
34 | * @var string $description |
||
35 | */ |
||
36 | protected $description; |
||
37 | |||
38 | /** |
||
39 | * @var callable $formatter |
||
40 | */ |
||
41 | protected $formatter; |
||
42 | |||
43 | /** |
||
44 | * @var callable $resolve |
||
45 | */ |
||
46 | protected $resolver; |
||
47 | |||
48 | /** |
||
49 | * @var array $args |
||
50 | */ |
||
51 | protected $args; |
||
52 | |||
53 | /** |
||
54 | * @var array $caps |
||
55 | */ |
||
56 | protected $caps; |
||
57 | |||
58 | /** |
||
59 | * @var bool $use_for_input |
||
60 | */ |
||
61 | protected $use_for_input = true; |
||
62 | |||
63 | /** |
||
64 | * @var bool $use_for_output |
||
65 | */ |
||
66 | protected $use_for_output = true; |
||
67 | |||
68 | |||
69 | /** |
||
70 | * @param string $name |
||
71 | * @param string|string[] $type |
||
72 | * @param string|null $key |
||
73 | * @param string $description |
||
74 | * @param callable|null $formatter |
||
75 | * @param callable|null $resolver |
||
76 | * @param array $caps |
||
77 | */ |
||
78 | public function __construct( |
||
97 | |||
98 | |||
99 | /** |
||
100 | * @return array |
||
101 | */ |
||
102 | public function args() |
||
106 | |||
107 | |||
108 | /** |
||
109 | * @return array |
||
110 | */ |
||
111 | public function caps() |
||
115 | |||
116 | |||
117 | /** |
||
118 | * @return string |
||
119 | */ |
||
120 | public function description() |
||
124 | |||
125 | |||
126 | /** |
||
127 | * @return string |
||
128 | */ |
||
129 | public function key() |
||
133 | |||
134 | |||
135 | /** |
||
136 | * @return string |
||
137 | */ |
||
138 | public function name() |
||
142 | |||
143 | |||
144 | /** |
||
145 | * @return string|string[] |
||
146 | */ |
||
147 | public function type() |
||
151 | |||
152 | |||
153 | /** |
||
154 | * Convert the field to array to be |
||
155 | * able to pass as config to WP GraphQL |
||
156 | * |
||
157 | * @return array |
||
158 | */ |
||
159 | public function toArray() |
||
163 | |||
164 | |||
165 | /** |
||
166 | * Sets the value for use_for_input. |
||
167 | * |
||
168 | * @param bool $use_for_input |
||
169 | */ |
||
170 | protected function setUseForInput($use_for_input) |
||
174 | |||
175 | |||
176 | /** |
||
177 | * Whether the field should be used for |
||
178 | * mutation inputs. |
||
179 | * |
||
180 | * @return bool |
||
181 | */ |
||
182 | public function useForInput() |
||
186 | |||
187 | |||
188 | /** |
||
189 | * Whether the field should be used for |
||
190 | * query outputs. |
||
191 | * |
||
192 | * @return bool |
||
193 | */ |
||
194 | public function useForOutput() |
||
198 | |||
199 | |||
200 | /** |
||
201 | * Sets the value for use_for_output |
||
202 | * |
||
203 | * @param bool $use_for_output |
||
204 | */ |
||
205 | protected function setUseForOutput($use_for_output) |
||
209 | |||
210 | |||
211 | /** |
||
212 | * Whether the field should resolve |
||
213 | * based on the user caps etc. |
||
214 | * |
||
215 | * @return boolean |
||
216 | */ |
||
217 | public function shouldResolve() |
||
226 | |||
227 | |||
228 | /** |
||
229 | * Whether the field has an explicit resolver set. |
||
230 | * |
||
231 | * @return boolean |
||
232 | */ |
||
233 | public function hasInternalResolver() |
||
237 | |||
238 | |||
239 | /** |
||
240 | * Whether the field has an explicit resolver set. |
||
241 | * |
||
242 | * @param mixed $source The source that's passed down the GraphQL queries |
||
243 | * @param array $args The inputArgs on the field |
||
244 | * @param AppContext $context The AppContext passed down the GraphQL tree |
||
245 | * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
||
246 | * @return mixed |
||
247 | * @throws LogicException |
||
248 | */ |
||
249 | public function resolve($source, array $args, AppContext $context, ResolveInfo $info) |
||
259 | |||
260 | |||
261 | /** |
||
262 | * Checks if the format callback is set. |
||
263 | * If yes, then uses it to format the value. |
||
264 | * |
||
265 | * @param mixed $value |
||
266 | * @return mixed The formatted value. |
||
267 | */ |
||
268 | public function mayBeFormatValue($value) |
||
278 | } |
||
279 |