@@ -20,89 +20,89 @@ |
||
20 | 20 | */ |
21 | 21 | class TypeCollection extends Collection |
22 | 22 | { |
23 | - const COLLECTION_NAME = 'espresso_graphql_types'; |
|
23 | + const COLLECTION_NAME = 'espresso_graphql_types'; |
|
24 | 24 | |
25 | - const COLLECTION_INTERFACE = 'EventEspresso\core\services\graphql\types\TypeInterface'; |
|
25 | + const COLLECTION_INTERFACE = 'EventEspresso\core\services\graphql\types\TypeInterface'; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var CollectionLoader $loader |
|
29 | - */ |
|
30 | - protected $loader; |
|
27 | + /** |
|
28 | + * @var CollectionLoader $loader |
|
29 | + */ |
|
30 | + protected $loader; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * TypeCollection constructor |
|
35 | - * |
|
36 | - * @throws InvalidInterfaceException |
|
37 | - */ |
|
38 | - public function __construct() |
|
39 | - { |
|
40 | - parent::__construct( |
|
41 | - TypeCollection::COLLECTION_INTERFACE, |
|
42 | - TypeCollection::COLLECTION_NAME |
|
43 | - ); |
|
44 | - } |
|
33 | + /** |
|
34 | + * TypeCollection constructor |
|
35 | + * |
|
36 | + * @throws InvalidInterfaceException |
|
37 | + */ |
|
38 | + public function __construct() |
|
39 | + { |
|
40 | + parent::__construct( |
|
41 | + TypeCollection::COLLECTION_INTERFACE, |
|
42 | + TypeCollection::COLLECTION_NAME |
|
43 | + ); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * @throws CollectionDetailsException |
|
49 | - * @throws CollectionLoaderException |
|
50 | - * @since $VID:$ |
|
51 | - */ |
|
52 | - private function loadCollection() |
|
53 | - { |
|
54 | - if (! $this->loader instanceof CollectionLoader) { |
|
55 | - $this->loader = new CollectionLoader( |
|
56 | - new CollectionDetails( |
|
57 | - // collection name |
|
58 | - TypeCollection::COLLECTION_NAME, |
|
59 | - // collection interface |
|
60 | - TypeCollection::COLLECTION_INTERFACE, |
|
61 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
62 | - apply_filters( |
|
63 | - 'FHEE__EventEspresso_core_services_graphql_TypeCollection__loadCollection__collection_FQCNs', |
|
64 | - ['EventEspresso\core\domain\services\graphql\types'] |
|
65 | - ), |
|
66 | - // filepaths to classes to add |
|
67 | - array(), |
|
68 | - // file mask to use if parsing folder for files to add |
|
69 | - '', |
|
70 | - // what to use as identifier for collection entities |
|
71 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
72 | - CollectionDetails::ID_CLASS_NAME |
|
73 | - ), |
|
74 | - $this |
|
75 | - ); |
|
76 | - } |
|
77 | - } |
|
47 | + /** |
|
48 | + * @throws CollectionDetailsException |
|
49 | + * @throws CollectionLoaderException |
|
50 | + * @since $VID:$ |
|
51 | + */ |
|
52 | + private function loadCollection() |
|
53 | + { |
|
54 | + if (! $this->loader instanceof CollectionLoader) { |
|
55 | + $this->loader = new CollectionLoader( |
|
56 | + new CollectionDetails( |
|
57 | + // collection name |
|
58 | + TypeCollection::COLLECTION_NAME, |
|
59 | + // collection interface |
|
60 | + TypeCollection::COLLECTION_INTERFACE, |
|
61 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
62 | + apply_filters( |
|
63 | + 'FHEE__EventEspresso_core_services_graphql_TypeCollection__loadCollection__collection_FQCNs', |
|
64 | + ['EventEspresso\core\domain\services\graphql\types'] |
|
65 | + ), |
|
66 | + // filepaths to classes to add |
|
67 | + array(), |
|
68 | + // file mask to use if parsing folder for files to add |
|
69 | + '', |
|
70 | + // what to use as identifier for collection entities |
|
71 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
72 | + CollectionDetails::ID_CLASS_NAME |
|
73 | + ), |
|
74 | + $this |
|
75 | + ); |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * @return CollectionInterface |
|
82 | - * @throws CollectionDetailsException |
|
83 | - * @throws CollectionLoaderException |
|
84 | - * @since $VID:$ |
|
85 | - */ |
|
86 | - public function loadTypes() |
|
87 | - { |
|
88 | - $this->loadCollection(); |
|
89 | - return $this->loader->getCollection(); |
|
90 | - } |
|
80 | + /** |
|
81 | + * @return CollectionInterface |
|
82 | + * @throws CollectionDetailsException |
|
83 | + * @throws CollectionLoaderException |
|
84 | + * @since $VID:$ |
|
85 | + */ |
|
86 | + public function loadTypes() |
|
87 | + { |
|
88 | + $this->loadCollection(); |
|
89 | + return $this->loader->getCollection(); |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * getIdentifier |
|
95 | - * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
96 | - * If no $identifier is supplied, then the fully qualified class name is used |
|
97 | - * |
|
98 | - * @param $object |
|
99 | - * @param mixed $identifier |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - public function getIdentifier($object, $identifier = null) |
|
103 | - { |
|
104 | - return ! empty($identifier) |
|
105 | - ? $identifier |
|
106 | - : get_class($object); |
|
107 | - } |
|
93 | + /** |
|
94 | + * getIdentifier |
|
95 | + * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
96 | + * If no $identifier is supplied, then the fully qualified class name is used |
|
97 | + * |
|
98 | + * @param $object |
|
99 | + * @param mixed $identifier |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + public function getIdentifier($object, $identifier = null) |
|
103 | + { |
|
104 | + return ! empty($identifier) |
|
105 | + ? $identifier |
|
106 | + : get_class($object); |
|
107 | + } |
|
108 | 108 | } |
@@ -34,270 +34,270 @@ |
||
34 | 34 | */ |
35 | 35 | abstract class TypeBase implements TypeInterface |
36 | 36 | { |
37 | - /** |
|
38 | - * @var string $namespace The graphql namespace/prefix. |
|
39 | - */ |
|
40 | - protected $namespace = 'Espresso'; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EEM_Base $model |
|
44 | - */ |
|
45 | - protected $model; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var string $name |
|
49 | - */ |
|
50 | - protected $name = ''; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var string $description |
|
54 | - */ |
|
55 | - protected $description = ''; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var GraphQLFieldInterface[] $fields |
|
59 | - */ |
|
60 | - protected $fields = []; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var array $graphql_to_model_map |
|
64 | - */ |
|
65 | - protected $graphql_to_model_map = []; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var FieldResolver $field_resolver |
|
69 | - */ |
|
70 | - protected $field_resolver; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var bool $is_custom_post_type |
|
74 | - */ |
|
75 | - protected $is_custom_post_type = false; |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * TypeBase constructor. |
|
80 | - * |
|
81 | - * @param EEM_Base|null $model |
|
82 | - */ |
|
83 | - public function __construct(EEM_Base $model = null) |
|
84 | - { |
|
85 | - $this->model = $model; |
|
86 | - $this->setFields($this->getFields()); |
|
87 | - $this->field_resolver = new FieldResolver( |
|
88 | - $this->model, |
|
89 | - $this->getFieldsForResolver() |
|
90 | - ); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @return GraphQLFieldInterface[] |
|
96 | - * @since $VID:$ |
|
97 | - */ |
|
98 | - abstract protected function getFields(): array; |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public function name(): string |
|
105 | - { |
|
106 | - return $this->name; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @param string $name |
|
112 | - */ |
|
113 | - protected function setName(string $name) |
|
114 | - { |
|
115 | - $this->name = $name; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function description(): string |
|
123 | - { |
|
124 | - return $this->description; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param string $description |
|
130 | - */ |
|
131 | - protected function setDescription(string $description) |
|
132 | - { |
|
133 | - $this->description = $description; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @return GraphQLFieldInterface[] |
|
139 | - * @since $VID:$ |
|
140 | - */ |
|
141 | - public function fields(): array |
|
142 | - { |
|
143 | - return (array) $this->fields; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @param GraphQLFieldInterface[] $fields |
|
149 | - */ |
|
150 | - protected function setFields(array $fields) |
|
151 | - { |
|
152 | - foreach ($fields as $field) { |
|
153 | - if ($field instanceof GraphQLField) { |
|
154 | - $this->fields[] = $field; |
|
155 | - } |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * Creates a key map for internal resolver. |
|
162 | - * |
|
163 | - * @return array |
|
164 | - * @since $VID:$ |
|
165 | - */ |
|
166 | - public function getFieldsForResolver(): array |
|
167 | - { |
|
168 | - $fields = []; |
|
169 | - foreach ($this->fields() as $field) { |
|
170 | - if ($field->useForOutput()) { |
|
171 | - $fields[ $field->name() ] = $field; |
|
172 | - } |
|
173 | - } |
|
174 | - return $fields; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - public function isCustomPostType(): bool |
|
182 | - { |
|
183 | - return $this->is_custom_post_type; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @param bool $is_custom_post_type |
|
189 | - */ |
|
190 | - protected function setIsCustomPostType(bool $is_custom_post_type) |
|
191 | - { |
|
192 | - $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @param int|float $value |
|
198 | - * @return int |
|
199 | - * @since $VID:$ |
|
200 | - */ |
|
201 | - public function parseInfiniteValue($value): int |
|
202 | - { |
|
203 | - $value = trim($value); |
|
204 | - return $value === null |
|
205 | - || $value === '' |
|
206 | - || $value === '∞' |
|
207 | - || $value === 'INF' |
|
208 | - || $value === INF |
|
209 | - || $value === EE_INF |
|
210 | - || is_infinite((float) $value) |
|
211 | - ? -1 |
|
212 | - : $value; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @param mixed $source |
|
218 | - * @return EE_Base_Class|null |
|
219 | - * @throws EE_Error |
|
220 | - */ |
|
221 | - private function getModel($source): ?EE_Base_Class |
|
222 | - { |
|
223 | - // If it comes from a custom connection |
|
224 | - // where the $source is already instantiated. |
|
225 | - if ($source instanceof EE_Base_Class) { |
|
226 | - return $source; |
|
227 | - } |
|
228 | - return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
234 | - * @param array $args The inputArgs on the field |
|
235 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
236 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
237 | - * @return EE_Base_Class|Deferred|string|null |
|
238 | - * @throws EE_Error |
|
239 | - * @throws InvalidDataTypeException |
|
240 | - * @throws InvalidInterfaceException |
|
241 | - * @throws UnexpectedEntityException |
|
242 | - * @throws UserError |
|
243 | - * @throws InvalidArgumentException |
|
244 | - * @throws ReflectionException |
|
245 | - * @since $VID:$ |
|
246 | - */ |
|
247 | - public function resolveField($source, array $args, AppContext $context, ResolveInfo $info) |
|
248 | - { |
|
249 | - $source = $source instanceof RootQuery ? $source : $this->getModel($source); |
|
250 | - |
|
251 | - return $this->field_resolver->resolve($source, $args, $context, $info); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @param mixed $payload The payload returned after mutation |
|
257 | - * @param array $args The inputArgs on the field |
|
258 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
259 | - * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null |
|
260 | - * @throws EE_Error |
|
261 | - */ |
|
262 | - public function resolveFromPayload($payload, array $args, AppContext $context) |
|
263 | - { |
|
264 | - if (empty($payload['id'])) { |
|
265 | - return null; |
|
266 | - } |
|
267 | - return $this->model->get_one_by_ID($payload['id']); |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * Prepares a datetime value in ISO8601/RFC3339 format. |
|
273 | - * It is assumed that the value of $datetime is in the format |
|
274 | - * returned by EE_Base_Class::get_format(). |
|
275 | - * |
|
276 | - * @param string $datetime The datetime value. |
|
277 | - * @param EE_Base_Class $source The source object. |
|
278 | - * @return string ISO8601/RFC3339 formatted datetime. |
|
279 | - */ |
|
280 | - public function formatDatetime(string $datetime, EE_Base_Class $source): string |
|
281 | - { |
|
282 | - $format = $source->get_format(); |
|
283 | - // create date object based on local timezone |
|
284 | - $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone())); |
|
285 | - // change the timezone to UTC |
|
286 | - $datetime->setTimezone(new DateTimeZone('UTC')); |
|
287 | - |
|
288 | - return $datetime->format(DateTime::RFC3339); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Converts an object to JSON. The object must have a "toJson" method. |
|
294 | - * |
|
295 | - * @param string $object The object/value. |
|
296 | - * @param EE_Base_Class $source The source object. |
|
297 | - * @return string JSON representation of the object. |
|
298 | - */ |
|
299 | - public function toJson(JsonableInterface $object, EE_Base_Class $source): string |
|
300 | - { |
|
301 | - return $object->toJson(); |
|
302 | - } |
|
37 | + /** |
|
38 | + * @var string $namespace The graphql namespace/prefix. |
|
39 | + */ |
|
40 | + protected $namespace = 'Espresso'; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EEM_Base $model |
|
44 | + */ |
|
45 | + protected $model; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var string $name |
|
49 | + */ |
|
50 | + protected $name = ''; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var string $description |
|
54 | + */ |
|
55 | + protected $description = ''; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var GraphQLFieldInterface[] $fields |
|
59 | + */ |
|
60 | + protected $fields = []; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var array $graphql_to_model_map |
|
64 | + */ |
|
65 | + protected $graphql_to_model_map = []; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var FieldResolver $field_resolver |
|
69 | + */ |
|
70 | + protected $field_resolver; |
|
71 | + |
|
72 | + /** |
|
73 | + * @var bool $is_custom_post_type |
|
74 | + */ |
|
75 | + protected $is_custom_post_type = false; |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * TypeBase constructor. |
|
80 | + * |
|
81 | + * @param EEM_Base|null $model |
|
82 | + */ |
|
83 | + public function __construct(EEM_Base $model = null) |
|
84 | + { |
|
85 | + $this->model = $model; |
|
86 | + $this->setFields($this->getFields()); |
|
87 | + $this->field_resolver = new FieldResolver( |
|
88 | + $this->model, |
|
89 | + $this->getFieldsForResolver() |
|
90 | + ); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @return GraphQLFieldInterface[] |
|
96 | + * @since $VID:$ |
|
97 | + */ |
|
98 | + abstract protected function getFields(): array; |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public function name(): string |
|
105 | + { |
|
106 | + return $this->name; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @param string $name |
|
112 | + */ |
|
113 | + protected function setName(string $name) |
|
114 | + { |
|
115 | + $this->name = $name; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function description(): string |
|
123 | + { |
|
124 | + return $this->description; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param string $description |
|
130 | + */ |
|
131 | + protected function setDescription(string $description) |
|
132 | + { |
|
133 | + $this->description = $description; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @return GraphQLFieldInterface[] |
|
139 | + * @since $VID:$ |
|
140 | + */ |
|
141 | + public function fields(): array |
|
142 | + { |
|
143 | + return (array) $this->fields; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @param GraphQLFieldInterface[] $fields |
|
149 | + */ |
|
150 | + protected function setFields(array $fields) |
|
151 | + { |
|
152 | + foreach ($fields as $field) { |
|
153 | + if ($field instanceof GraphQLField) { |
|
154 | + $this->fields[] = $field; |
|
155 | + } |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * Creates a key map for internal resolver. |
|
162 | + * |
|
163 | + * @return array |
|
164 | + * @since $VID:$ |
|
165 | + */ |
|
166 | + public function getFieldsForResolver(): array |
|
167 | + { |
|
168 | + $fields = []; |
|
169 | + foreach ($this->fields() as $field) { |
|
170 | + if ($field->useForOutput()) { |
|
171 | + $fields[ $field->name() ] = $field; |
|
172 | + } |
|
173 | + } |
|
174 | + return $fields; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + public function isCustomPostType(): bool |
|
182 | + { |
|
183 | + return $this->is_custom_post_type; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * @param bool $is_custom_post_type |
|
189 | + */ |
|
190 | + protected function setIsCustomPostType(bool $is_custom_post_type) |
|
191 | + { |
|
192 | + $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @param int|float $value |
|
198 | + * @return int |
|
199 | + * @since $VID:$ |
|
200 | + */ |
|
201 | + public function parseInfiniteValue($value): int |
|
202 | + { |
|
203 | + $value = trim($value); |
|
204 | + return $value === null |
|
205 | + || $value === '' |
|
206 | + || $value === '∞' |
|
207 | + || $value === 'INF' |
|
208 | + || $value === INF |
|
209 | + || $value === EE_INF |
|
210 | + || is_infinite((float) $value) |
|
211 | + ? -1 |
|
212 | + : $value; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @param mixed $source |
|
218 | + * @return EE_Base_Class|null |
|
219 | + * @throws EE_Error |
|
220 | + */ |
|
221 | + private function getModel($source): ?EE_Base_Class |
|
222 | + { |
|
223 | + // If it comes from a custom connection |
|
224 | + // where the $source is already instantiated. |
|
225 | + if ($source instanceof EE_Base_Class) { |
|
226 | + return $source; |
|
227 | + } |
|
228 | + return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
234 | + * @param array $args The inputArgs on the field |
|
235 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
236 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
237 | + * @return EE_Base_Class|Deferred|string|null |
|
238 | + * @throws EE_Error |
|
239 | + * @throws InvalidDataTypeException |
|
240 | + * @throws InvalidInterfaceException |
|
241 | + * @throws UnexpectedEntityException |
|
242 | + * @throws UserError |
|
243 | + * @throws InvalidArgumentException |
|
244 | + * @throws ReflectionException |
|
245 | + * @since $VID:$ |
|
246 | + */ |
|
247 | + public function resolveField($source, array $args, AppContext $context, ResolveInfo $info) |
|
248 | + { |
|
249 | + $source = $source instanceof RootQuery ? $source : $this->getModel($source); |
|
250 | + |
|
251 | + return $this->field_resolver->resolve($source, $args, $context, $info); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @param mixed $payload The payload returned after mutation |
|
257 | + * @param array $args The inputArgs on the field |
|
258 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
259 | + * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null |
|
260 | + * @throws EE_Error |
|
261 | + */ |
|
262 | + public function resolveFromPayload($payload, array $args, AppContext $context) |
|
263 | + { |
|
264 | + if (empty($payload['id'])) { |
|
265 | + return null; |
|
266 | + } |
|
267 | + return $this->model->get_one_by_ID($payload['id']); |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * Prepares a datetime value in ISO8601/RFC3339 format. |
|
273 | + * It is assumed that the value of $datetime is in the format |
|
274 | + * returned by EE_Base_Class::get_format(). |
|
275 | + * |
|
276 | + * @param string $datetime The datetime value. |
|
277 | + * @param EE_Base_Class $source The source object. |
|
278 | + * @return string ISO8601/RFC3339 formatted datetime. |
|
279 | + */ |
|
280 | + public function formatDatetime(string $datetime, EE_Base_Class $source): string |
|
281 | + { |
|
282 | + $format = $source->get_format(); |
|
283 | + // create date object based on local timezone |
|
284 | + $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone())); |
|
285 | + // change the timezone to UTC |
|
286 | + $datetime->setTimezone(new DateTimeZone('UTC')); |
|
287 | + |
|
288 | + return $datetime->format(DateTime::RFC3339); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Converts an object to JSON. The object must have a "toJson" method. |
|
294 | + * |
|
295 | + * @param string $object The object/value. |
|
296 | + * @param EE_Base_Class $source The source object. |
|
297 | + * @return string JSON representation of the object. |
|
298 | + */ |
|
299 | + public function toJson(JsonableInterface $object, EE_Base_Class $source): string |
|
300 | + { |
|
301 | + return $object->toJson(); |
|
302 | + } |
|
303 | 303 | } |
@@ -23,79 +23,79 @@ |
||
23 | 23 | */ |
24 | 24 | interface TypeInterface |
25 | 25 | { |
26 | - /** |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function name(): string; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function description(): string; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @return GraphQLFieldInterface[] |
|
40 | - * @since $VID:$ |
|
41 | - */ |
|
42 | - public function fields(): array; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Creates a key map for internal resolver. |
|
47 | - * |
|
48 | - * @return array |
|
49 | - * @since $VID:$ |
|
50 | - */ |
|
51 | - public function getFieldsForResolver(): array; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public function isCustomPostType(): bool; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @param int|float $value |
|
62 | - * @return int |
|
63 | - * @since $VID:$ |
|
64 | - */ |
|
65 | - public function parseInfiniteValue($value): int; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
70 | - * @param array $args The inputArgs on the field |
|
71 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
72 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
73 | - * @return mixed |
|
74 | - * @throws EE_Error |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws InvalidInterfaceException |
|
77 | - * @throws UnexpectedEntityException |
|
78 | - * @throws UserError |
|
79 | - * @throws InvalidArgumentException |
|
80 | - * @throws ReflectionException |
|
81 | - * @since $VID:$ |
|
82 | - */ |
|
83 | - public function resolveField($source, array $args, AppContext $context, ResolveInfo $info); |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param mixed $payload The payload returned after mutation |
|
88 | - * @param array $args The inputArgs on the field |
|
89 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
90 | - * @return string|null |
|
91 | - * @throws EE_Error |
|
92 | - * @throws InvalidDataTypeException |
|
93 | - * @throws InvalidInterfaceException |
|
94 | - * @throws UnexpectedEntityException |
|
95 | - * @throws UserError |
|
96 | - * @throws InvalidArgumentException |
|
97 | - * @throws ReflectionException |
|
98 | - * @since $VID:$ |
|
99 | - */ |
|
100 | - public function resolveFromPayload($payload, array $args, AppContext $context); |
|
26 | + /** |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function name(): string; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function description(): string; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @return GraphQLFieldInterface[] |
|
40 | + * @since $VID:$ |
|
41 | + */ |
|
42 | + public function fields(): array; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Creates a key map for internal resolver. |
|
47 | + * |
|
48 | + * @return array |
|
49 | + * @since $VID:$ |
|
50 | + */ |
|
51 | + public function getFieldsForResolver(): array; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public function isCustomPostType(): bool; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @param int|float $value |
|
62 | + * @return int |
|
63 | + * @since $VID:$ |
|
64 | + */ |
|
65 | + public function parseInfiniteValue($value): int; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
70 | + * @param array $args The inputArgs on the field |
|
71 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
72 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
73 | + * @return mixed |
|
74 | + * @throws EE_Error |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws InvalidInterfaceException |
|
77 | + * @throws UnexpectedEntityException |
|
78 | + * @throws UserError |
|
79 | + * @throws InvalidArgumentException |
|
80 | + * @throws ReflectionException |
|
81 | + * @since $VID:$ |
|
82 | + */ |
|
83 | + public function resolveField($source, array $args, AppContext $context, ResolveInfo $info); |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param mixed $payload The payload returned after mutation |
|
88 | + * @param array $args The inputArgs on the field |
|
89 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
90 | + * @return string|null |
|
91 | + * @throws EE_Error |
|
92 | + * @throws InvalidDataTypeException |
|
93 | + * @throws InvalidInterfaceException |
|
94 | + * @throws UnexpectedEntityException |
|
95 | + * @throws UserError |
|
96 | + * @throws InvalidArgumentException |
|
97 | + * @throws ReflectionException |
|
98 | + * @since $VID:$ |
|
99 | + */ |
|
100 | + public function resolveFromPayload($payload, array $args, AppContext $context); |
|
101 | 101 | } |
@@ -14,21 +14,21 @@ |
||
14 | 14 | */ |
15 | 15 | interface InputInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function name(); |
|
17 | + /** |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function name(); |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function description(); |
|
23 | + /** |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function description(); |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @return \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] |
|
31 | - * @since $VID:$ |
|
32 | - */ |
|
33 | - public function fields(); |
|
29 | + /** |
|
30 | + * @return \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] |
|
31 | + * @since $VID:$ |
|
32 | + */ |
|
33 | + public function fields(); |
|
34 | 34 | } |
@@ -15,97 +15,97 @@ |
||
15 | 15 | */ |
16 | 16 | abstract class InputBase implements InputInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * @var string $namespace The graphql namespace/prefix. |
|
20 | - */ |
|
21 | - protected $namespace = 'Espresso'; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var string $name |
|
25 | - */ |
|
26 | - protected $name = ''; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var string $description |
|
30 | - */ |
|
31 | - protected $description = ''; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var GraphQLFieldInterface[] $fields |
|
35 | - */ |
|
36 | - protected $fields = []; |
|
37 | - |
|
38 | - /** |
|
39 | - * InputBase constructor. |
|
40 | - */ |
|
41 | - public function __construct() |
|
42 | - { |
|
43 | - $this->setFields($this->getFields()); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @return GraphQLFieldInterface[] |
|
49 | - * @since $VID:$ |
|
50 | - */ |
|
51 | - abstract protected function getFields(); |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function name() |
|
58 | - { |
|
59 | - return $this->name; |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @param string $name |
|
65 | - */ |
|
66 | - protected function setName($name) |
|
67 | - { |
|
68 | - $this->name = $name; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function description() |
|
76 | - { |
|
77 | - return $this->description; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @param string $description |
|
83 | - */ |
|
84 | - protected function setDescription($description) |
|
85 | - { |
|
86 | - $this->description = $description; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @return GraphQLFieldInterface[] |
|
92 | - * @since $VID:$ |
|
93 | - */ |
|
94 | - public function fields() |
|
95 | - { |
|
96 | - return (array) $this->fields; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @param GraphQLFieldInterface[] $fields |
|
102 | - */ |
|
103 | - protected function setFields(array $fields) |
|
104 | - { |
|
105 | - foreach ($fields as $field) { |
|
106 | - if ($field instanceof GraphQLField) { |
|
107 | - $this->fields[] = $field; |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
18 | + /** |
|
19 | + * @var string $namespace The graphql namespace/prefix. |
|
20 | + */ |
|
21 | + protected $namespace = 'Espresso'; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var string $name |
|
25 | + */ |
|
26 | + protected $name = ''; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var string $description |
|
30 | + */ |
|
31 | + protected $description = ''; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var GraphQLFieldInterface[] $fields |
|
35 | + */ |
|
36 | + protected $fields = []; |
|
37 | + |
|
38 | + /** |
|
39 | + * InputBase constructor. |
|
40 | + */ |
|
41 | + public function __construct() |
|
42 | + { |
|
43 | + $this->setFields($this->getFields()); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @return GraphQLFieldInterface[] |
|
49 | + * @since $VID:$ |
|
50 | + */ |
|
51 | + abstract protected function getFields(); |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function name() |
|
58 | + { |
|
59 | + return $this->name; |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @param string $name |
|
65 | + */ |
|
66 | + protected function setName($name) |
|
67 | + { |
|
68 | + $this->name = $name; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function description() |
|
76 | + { |
|
77 | + return $this->description; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @param string $description |
|
83 | + */ |
|
84 | + protected function setDescription($description) |
|
85 | + { |
|
86 | + $this->description = $description; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @return GraphQLFieldInterface[] |
|
92 | + * @since $VID:$ |
|
93 | + */ |
|
94 | + public function fields() |
|
95 | + { |
|
96 | + return (array) $this->fields; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @param GraphQLFieldInterface[] $fields |
|
102 | + */ |
|
103 | + protected function setFields(array $fields) |
|
104 | + { |
|
105 | + foreach ($fields as $field) { |
|
106 | + if ($field instanceof GraphQLField) { |
|
107 | + $this->fields[] = $field; |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | 111 | } |
@@ -15,10 +15,10 @@ |
||
15 | 15 | */ |
16 | 16 | interface GQLManagerInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * @throws CollectionDetailsException |
|
20 | - * @throws CollectionLoaderException |
|
21 | - * @since $VID:$ |
|
22 | - */ |
|
23 | - public function init(); |
|
18 | + /** |
|
19 | + * @throws CollectionDetailsException |
|
20 | + * @throws CollectionLoaderException |
|
21 | + * @since $VID:$ |
|
22 | + */ |
|
23 | + public function init(); |
|
24 | 24 | } |
@@ -12,21 +12,21 @@ |
||
12 | 12 | */ |
13 | 13 | interface EnumInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public function name(); |
|
15 | + /** |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public function name(); |
|
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public function description(); |
|
21 | + /** |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public function description(); |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @return array |
|
29 | - * @since $VID:$ |
|
30 | - */ |
|
31 | - public function values(); |
|
27 | + /** |
|
28 | + * @return array |
|
29 | + * @since $VID:$ |
|
30 | + */ |
|
31 | + public function values(); |
|
32 | 32 | } |
@@ -20,86 +20,86 @@ |
||
20 | 20 | */ |
21 | 21 | class ResolverCollection extends Collection |
22 | 22 | { |
23 | - const COLLECTION_NAME = 'espresso_graphql_resolvers'; |
|
23 | + const COLLECTION_NAME = 'espresso_graphql_resolvers'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var CollectionLoader $loader |
|
27 | - */ |
|
28 | - protected $loader; |
|
25 | + /** |
|
26 | + * @var CollectionLoader $loader |
|
27 | + */ |
|
28 | + protected $loader; |
|
29 | 29 | |
30 | - /** |
|
31 | - * ResolverCollection constructor |
|
32 | - * |
|
33 | - * @throws InvalidInterfaceException |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - parent::__construct( |
|
38 | - 'EventEspresso\core\services\graphql\ResolverInterface', |
|
39 | - ResolverCollection::COLLECTION_NAME |
|
40 | - ); |
|
41 | - } |
|
30 | + /** |
|
31 | + * ResolverCollection constructor |
|
32 | + * |
|
33 | + * @throws InvalidInterfaceException |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + parent::__construct( |
|
38 | + 'EventEspresso\core\services\graphql\ResolverInterface', |
|
39 | + ResolverCollection::COLLECTION_NAME |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @throws CollectionDetailsException |
|
46 | - * @throws CollectionLoaderException |
|
47 | - * @since $VID:$ |
|
48 | - */ |
|
49 | - private function loadCollection() |
|
50 | - { |
|
51 | - if (! $this->loader instanceof CollectionLoader) { |
|
52 | - $this->loader = new CollectionLoader( |
|
53 | - new CollectionDetails( |
|
54 | - // collection name |
|
55 | - ResolverCollection::COLLECTION_NAME, |
|
56 | - // collection interface |
|
57 | - 'EventEspresso\core\services\graphql\ResolverInterface', |
|
58 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
59 | - apply_filters( |
|
60 | - 'FHEE__EventEspresso_core_services_graphql_ResolverCollection__loadCollection__collection_FQCNs', |
|
61 | - ['EventEspresso\core\domain\services\graphql\resolvers'] |
|
62 | - ), |
|
63 | - // filepaths to classes to add |
|
64 | - array(), |
|
65 | - // file mask to use if parsing folder for files to add |
|
66 | - '', |
|
67 | - // what to use as identifier for collection entities |
|
68 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
69 | - CollectionDetails::ID_CLASS_NAME |
|
70 | - ), |
|
71 | - $this |
|
72 | - ); |
|
73 | - } |
|
74 | - } |
|
44 | + /** |
|
45 | + * @throws CollectionDetailsException |
|
46 | + * @throws CollectionLoaderException |
|
47 | + * @since $VID:$ |
|
48 | + */ |
|
49 | + private function loadCollection() |
|
50 | + { |
|
51 | + if (! $this->loader instanceof CollectionLoader) { |
|
52 | + $this->loader = new CollectionLoader( |
|
53 | + new CollectionDetails( |
|
54 | + // collection name |
|
55 | + ResolverCollection::COLLECTION_NAME, |
|
56 | + // collection interface |
|
57 | + 'EventEspresso\core\services\graphql\ResolverInterface', |
|
58 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
59 | + apply_filters( |
|
60 | + 'FHEE__EventEspresso_core_services_graphql_ResolverCollection__loadCollection__collection_FQCNs', |
|
61 | + ['EventEspresso\core\domain\services\graphql\resolvers'] |
|
62 | + ), |
|
63 | + // filepaths to classes to add |
|
64 | + array(), |
|
65 | + // file mask to use if parsing folder for files to add |
|
66 | + '', |
|
67 | + // what to use as identifier for collection entities |
|
68 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
69 | + CollectionDetails::ID_CLASS_NAME |
|
70 | + ), |
|
71 | + $this |
|
72 | + ); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * @return CollectionInterface |
|
79 | - * @throws CollectionDetailsException |
|
80 | - * @throws CollectionLoaderException |
|
81 | - * @since $VID:$ |
|
82 | - */ |
|
83 | - public function loadResolvers() |
|
84 | - { |
|
85 | - $this->loadCollection(); |
|
86 | - return $this->loader->getCollection(); |
|
87 | - } |
|
77 | + /** |
|
78 | + * @return CollectionInterface |
|
79 | + * @throws CollectionDetailsException |
|
80 | + * @throws CollectionLoaderException |
|
81 | + * @since $VID:$ |
|
82 | + */ |
|
83 | + public function loadResolvers() |
|
84 | + { |
|
85 | + $this->loadCollection(); |
|
86 | + return $this->loader->getCollection(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * getIdentifier |
|
92 | - * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
93 | - * If no $identifier is supplied, then the fully qualified class name is used |
|
94 | - * |
|
95 | - * @param $object |
|
96 | - * @param mixed $identifier |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function getIdentifier($object, $identifier = null) |
|
100 | - { |
|
101 | - return ! empty($identifier) |
|
102 | - ? $identifier |
|
103 | - : get_class($object); |
|
104 | - } |
|
90 | + /** |
|
91 | + * getIdentifier |
|
92 | + * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
93 | + * If no $identifier is supplied, then the fully qualified class name is used |
|
94 | + * |
|
95 | + * @param $object |
|
96 | + * @param mixed $identifier |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function getIdentifier($object, $identifier = null) |
|
100 | + { |
|
101 | + return ! empty($identifier) |
|
102 | + ? $identifier |
|
103 | + : get_class($object); |
|
104 | + } |
|
105 | 105 | } |
@@ -15,13 +15,13 @@ |
||
15 | 15 | */ |
16 | 16 | interface ResolverInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * @param $source |
|
20 | - * @param array $args |
|
21 | - * @param AppContext $context |
|
22 | - * @param ResolveInfo $info |
|
23 | - * @return mixed |
|
24 | - * @since $VID:$ |
|
25 | - */ |
|
26 | - public function resolve($source, array $args, AppContext $context, ResolveInfo $info); |
|
18 | + /** |
|
19 | + * @param $source |
|
20 | + * @param array $args |
|
21 | + * @param AppContext $context |
|
22 | + * @param ResolveInfo $info |
|
23 | + * @return mixed |
|
24 | + * @since $VID:$ |
|
25 | + */ |
|
26 | + public function resolve($source, array $args, AppContext $context, ResolveInfo $info); |
|
27 | 27 | } |