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 $caps |
||
50 | */ |
||
51 | protected $caps; |
||
52 | |||
53 | /** |
||
54 | * @var bool $use_for_input |
||
55 | */ |
||
56 | protected $use_for_input = true; |
||
57 | |||
58 | /** |
||
59 | * @var bool $use_for_output |
||
60 | */ |
||
61 | protected $use_for_output = true; |
||
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( |
||
90 | |||
91 | |||
92 | /** |
||
93 | * @return array |
||
94 | */ |
||
95 | public function caps() |
||
99 | |||
100 | |||
101 | /** |
||
102 | * @return string |
||
103 | */ |
||
104 | public function description() |
||
108 | |||
109 | |||
110 | /** |
||
111 | * @return string |
||
112 | */ |
||
113 | public function key() |
||
117 | |||
118 | |||
119 | /** |
||
120 | * @return string |
||
121 | */ |
||
122 | public function name() |
||
126 | |||
127 | |||
128 | /** |
||
129 | * @return string|string[] |
||
130 | */ |
||
131 | public function type() |
||
135 | |||
136 | |||
137 | /** |
||
138 | * Convert the field to array to be |
||
139 | * able to pass as config to WP GraphQL |
||
140 | * |
||
141 | * @return array |
||
142 | */ |
||
143 | public function toArray() |
||
147 | |||
148 | |||
149 | /** |
||
150 | * Sets the value for use_for_input. |
||
151 | * |
||
152 | * @param bool $use_for_input |
||
153 | * |
||
154 | */ |
||
155 | protected function setUseForInput($use_for_input) |
||
159 | |||
160 | |||
161 | /** |
||
162 | * Whether the field should be used for |
||
163 | * mutation inputs. |
||
164 | * |
||
165 | * @return bool |
||
166 | */ |
||
167 | public function useForInput() |
||
171 | |||
172 | |||
173 | /** |
||
174 | * Whether the field should be used for |
||
175 | * query outputs. |
||
176 | * |
||
177 | * @return bool |
||
178 | */ |
||
179 | public function useForOutput() |
||
183 | |||
184 | |||
185 | /** |
||
186 | * Sets the value for use_for_output |
||
187 | * |
||
188 | * @param bool $use_for_output |
||
189 | */ |
||
190 | protected function setUseForOutput($use_for_output) |
||
194 | |||
195 | |||
196 | /** |
||
197 | * Whether the field should resolve |
||
198 | * based on the user caps etc. |
||
199 | * |
||
200 | * @return boolean |
||
201 | */ |
||
202 | public function shouldResolve() |
||
211 | |||
212 | |||
213 | /** |
||
214 | * Whether the field has an explicit resolver set. |
||
215 | * |
||
216 | * @return boolean |
||
217 | */ |
||
218 | public function hasInternalResolver() |
||
222 | |||
223 | |||
224 | /** |
||
225 | * Whether the field has an explicit resolver set. |
||
226 | * |
||
227 | * @param mixed $source The source that's passed down the GraphQL queries |
||
228 | * @param array $args The inputArgs on the field |
||
229 | * @param AppContext $context The AppContext passed down the GraphQL tree |
||
230 | * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
||
231 | * @return mixed |
||
232 | * @throws LogicException |
||
233 | */ |
||
234 | public function resolve($source, array $args, AppContext $context, ResolveInfo $info) |
||
244 | |||
245 | |||
246 | /** |
||
247 | * Checks if the format callback is set. |
||
248 | * If yes, then uses it to format the value. |
||
249 | * |
||
250 | * @param mixed $value |
||
251 | * @return mixed The formatted value. |
||
252 | */ |
||
253 | public function mayBeFormatValue($value) |
||
263 | } |
||
264 |