1 | <?php |
||
15 | class GraphQLField |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @var array $caps |
||
20 | */ |
||
21 | protected $caps; |
||
22 | |||
23 | /** |
||
24 | * @var string $description |
||
25 | */ |
||
26 | protected $description; |
||
27 | |||
28 | /** |
||
29 | * @var callable $formatter |
||
30 | */ |
||
31 | protected $formatter; |
||
32 | |||
33 | /** |
||
34 | * @var string|null $key |
||
35 | */ |
||
36 | protected $key; |
||
37 | |||
38 | /** |
||
39 | * @var string $name |
||
40 | */ |
||
41 | protected $name; |
||
42 | |||
43 | /** |
||
44 | * @var callable $resolve |
||
45 | */ |
||
46 | protected $resolver; |
||
47 | |||
48 | /** |
||
49 | * @var string|string[] $type |
||
50 | */ |
||
51 | protected $type; |
||
52 | |||
53 | |||
54 | /** |
||
55 | * @param string $name |
||
56 | * @param string|string[] $type |
||
57 | * @param string|null $key |
||
58 | * @param string $description |
||
59 | * @param callable|null $formatter |
||
60 | * @param callable|null $resolver |
||
61 | * @param array $caps |
||
62 | */ |
||
63 | public function __construct( |
||
80 | |||
81 | |||
82 | /** |
||
83 | * @return array |
||
84 | */ |
||
85 | public function caps() |
||
89 | |||
90 | |||
91 | /** |
||
92 | * @return string |
||
93 | */ |
||
94 | public function description() |
||
98 | |||
99 | |||
100 | /** |
||
101 | * @return string |
||
102 | */ |
||
103 | public function key() |
||
107 | |||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | public function name() |
||
116 | |||
117 | |||
118 | /** |
||
119 | * @return string|string[] |
||
120 | */ |
||
121 | public function type() |
||
125 | |||
126 | |||
127 | |||
128 | |||
129 | /** |
||
130 | * Whether the field should resolve |
||
131 | * based on the user caps etc. |
||
132 | * |
||
133 | * @return boolean |
||
134 | */ |
||
135 | public function shouldResolve() |
||
144 | |||
145 | |||
146 | /** |
||
147 | * Whether the field has an explicit resolver set. |
||
148 | * |
||
149 | * @return boolean |
||
150 | */ |
||
151 | public function hasInternalResolver() |
||
155 | |||
156 | |||
157 | /** |
||
158 | * Whether the field has an explicit resolver set. |
||
159 | * |
||
160 | * @param mixed $source The source that's passed down the GraphQL queries |
||
161 | * @param array $args The inputArgs on the field |
||
162 | * @param AppContext $context The AppContext passed down the GraphQL tree |
||
163 | * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
||
164 | * @return mixed |
||
165 | * @throws LogicException |
||
166 | */ |
||
167 | public function resolve($source, array $args, AppContext $context, ResolveInfo $info) |
||
177 | |||
178 | |||
179 | /** |
||
180 | * Checks if the format callback is set. |
||
181 | * If yes, then uses it to format the value. |
||
182 | * |
||
183 | * @param mixed $value |
||
184 | * @return mixed The formatted value. |
||
185 | */ |
||
186 | public function mayBeFormatValue($value) |
||
196 | |||
197 | |||
198 | /** |
||
199 | * Convert the field to array to be |
||
200 | * able to pass as config to WP GraphQL |
||
201 | * |
||
202 | * @return array |
||
203 | */ |
||
204 | public function toArray() |
||
208 | } |
||
209 |