1 | <?php |
||
15 | class GraphQLField |
||
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 $caps |
||
50 | */ |
||
51 | protected $caps; |
||
52 | |||
53 | /** |
||
54 | * @var bool $use_for_input |
||
55 | */ |
||
56 | protected $use_for_input; |
||
57 | |||
58 | /** |
||
59 | * @var bool $use_for_output |
||
60 | */ |
||
61 | protected $use_for_output; |
||
62 | |||
63 | |||
64 | /** |
||
65 | * @param string $name |
||
66 | * @param string|string[] $type |
||
67 | * @param string|null $key |
||
68 | * @param string $description |
||
69 | * @param callable|null $formatter |
||
70 | * @param callable|null $resolver |
||
71 | * @param array $caps |
||
72 | */ |
||
73 | public function __construct( |
||
93 | |||
94 | |||
95 | /** |
||
96 | * @return array |
||
97 | */ |
||
98 | public function caps() |
||
102 | |||
103 | |||
104 | /** |
||
105 | * @return string |
||
106 | */ |
||
107 | public function description() |
||
111 | |||
112 | |||
113 | /** |
||
114 | * @return string |
||
115 | */ |
||
116 | public function key() |
||
120 | |||
121 | |||
122 | /** |
||
123 | * @return string |
||
124 | */ |
||
125 | public function name() |
||
129 | |||
130 | |||
131 | /** |
||
132 | * @return string|string[] |
||
133 | */ |
||
134 | public function type() |
||
138 | |||
139 | |||
140 | /** |
||
141 | * Convert the field to array to be |
||
142 | * able to pass as config to WP GraphQL |
||
143 | * |
||
144 | * @return array |
||
145 | */ |
||
146 | public function toArray() |
||
150 | |||
151 | |||
152 | /** |
||
153 | * Sets the value for use_for_input. |
||
154 | * |
||
155 | * @param bool $use_for_input |
||
156 | * |
||
157 | */ |
||
158 | protected function setUseForInput($use_for_input) |
||
162 | |||
163 | |||
164 | /** |
||
165 | * Whether the field should be used for |
||
166 | * mutation inputs. |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | public function useForInput() |
||
174 | |||
175 | |||
176 | /** |
||
177 | * Whether the field should be used for |
||
178 | * query outputs. |
||
179 | * |
||
180 | * @return bool |
||
181 | */ |
||
182 | public function useForOutput() |
||
186 | |||
187 | |||
188 | /** |
||
189 | * Sets the value for use_for_output |
||
190 | * |
||
191 | * @return array |
||
192 | */ |
||
193 | protected function setUseForOutput($use_for_output) |
||
197 | |||
198 | |||
199 | /** |
||
200 | * Whether the field should resolve |
||
201 | * based on the user caps etc. |
||
202 | * |
||
203 | * @return boolean |
||
204 | */ |
||
205 | public function shouldResolve() |
||
214 | |||
215 | |||
216 | /** |
||
217 | * Whether the field has an explicit resolver set. |
||
218 | * |
||
219 | * @return boolean |
||
220 | */ |
||
221 | public function hasInternalResolver() |
||
225 | |||
226 | |||
227 | /** |
||
228 | * Whether the field has an explicit resolver set. |
||
229 | * |
||
230 | * @param mixed $source The source that's passed down the GraphQL queries |
||
231 | * @param array $args The inputArgs on the field |
||
232 | * @param AppContext $context The AppContext passed down the GraphQL tree |
||
233 | * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
||
234 | * @return mixed |
||
235 | * @throws LogicException |
||
236 | */ |
||
237 | public function resolve($source, array $args, AppContext $context, ResolveInfo $info) |
||
247 | |||
248 | |||
249 | /** |
||
250 | * Checks if the format callback is set. |
||
251 | * If yes, then uses it to format the value. |
||
252 | * |
||
253 | * @param mixed $value |
||
254 | * @return mixed The formatted value. |
||
255 | */ |
||
256 | public function mayBeFormatValue($value) |
||
266 | } |
||
267 |