1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GraphQLAPI\GraphQLAPI\ModuleResolvers; |
6
|
|
|
|
7
|
|
|
use GraphQLAPI\GraphQLAPI\Plugin; |
8
|
|
|
use PoPSchema\Pages\TypeResolvers\PageTypeResolver; |
9
|
|
|
use PoPSchema\Posts\TypeResolvers\PostTypeResolver; |
10
|
|
|
use PoPSchema\Users\TypeResolvers\UserTypeResolver; |
11
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleSettings\Properties; |
12
|
|
|
use PoPSchema\Media\TypeResolvers\MediaTypeResolver; |
13
|
|
|
use PoPSchema\Comments\TypeResolvers\CommentTypeResolver; |
14
|
|
|
use PoPSchema\PostTags\TypeResolvers\PostTagTypeResolver; |
15
|
|
|
use GraphQLAPI\GraphQLAPI\PostTypes\GraphQLEndpointPostType; |
16
|
|
|
use PoPSchema\UserRolesWP\TypeResolvers\UserRoleTypeResolver; |
17
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleResolvers\ModuleResolverTrait; |
18
|
|
|
use GraphQLAPI\GraphQLAPI\PostTypes\GraphQLPersistedQueryPostType; |
19
|
|
|
use GraphQLAPI\GraphQLAPI\PostTypes\GraphQLCacheControlListPostType; |
20
|
|
|
use PoPSchema\CustomPosts\TypeResolvers\CustomPostUnionTypeResolver; |
21
|
|
|
use GraphQLAPI\GraphQLAPI\PostTypes\GraphQLAccessControlListPostType; |
22
|
|
|
use GraphQLAPI\GraphQLAPI\PostTypes\GraphQLSchemaConfigurationPostType; |
23
|
|
|
use GraphQLAPI\GraphQLAPI\PostTypes\GraphQLFieldDeprecationListPostType; |
24
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleResolvers\AbstractSchemaTypeModuleResolver; |
25
|
|
|
use PoPSchema\GenericCustomPosts\TypeResolvers\GenericCustomPostTypeResolver; |
26
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleResolvers\EndpointFunctionalityModuleResolver; |
27
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleResolvers\OperationalFunctionalityModuleResolver; |
28
|
|
|
|
29
|
|
|
class SchemaTypeModuleResolver extends AbstractSchemaTypeModuleResolver |
30
|
|
|
{ |
31
|
|
|
use ModuleResolverTrait { |
32
|
|
|
ModuleResolverTrait::hasDocumentation as upstreamHasDocumentation; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public const SCHEMA_CUSTOMPOSTS = Plugin::NAMESPACE . '\schema-customposts'; |
36
|
|
|
public const SCHEMA_GENERIC_CUSTOMPOSTS = Plugin::NAMESPACE . '\schema-generic-customposts'; |
37
|
|
|
public const SCHEMA_POSTS = Plugin::NAMESPACE . '\schema-posts'; |
38
|
|
|
public const SCHEMA_COMMENTS = Plugin::NAMESPACE . '\schema-comments'; |
39
|
|
|
public const SCHEMA_USERS = Plugin::NAMESPACE . '\schema-users'; |
40
|
|
|
public const SCHEMA_USER_ROLES = Plugin::NAMESPACE . '\schema-user-roles'; |
41
|
|
|
public const SCHEMA_PAGES = Plugin::NAMESPACE . '\schema-pages'; |
42
|
|
|
public const SCHEMA_MEDIA = Plugin::NAMESPACE . '\schema-media'; |
43
|
|
|
public const SCHEMA_TAGS = Plugin::NAMESPACE . '\schema-tags'; |
44
|
|
|
public const SCHEMA_POST_TAGS = Plugin::NAMESPACE . '\schema-post-tags'; |
45
|
|
|
public const SCHEMA_USER_STATE_MUTATIONS = Plugin::NAMESPACE . '\schema-user-state-mutations'; |
46
|
|
|
public const SCHEMA_CUSTOMPOST_MUTATIONS = Plugin::NAMESPACE . '\schema-custompost-mutations'; |
47
|
|
|
public const SCHEMA_POST_MUTATIONS = Plugin::NAMESPACE . '\schema-post-mutations'; |
48
|
|
|
public const SCHEMA_CUSTOMPOSTMEDIA_MUTATIONS = Plugin::NAMESPACE . '\schema-custompostmedia-mutations'; |
49
|
|
|
public const SCHEMA_COMMENT_MUTATIONS = Plugin::NAMESPACE . '\schema-comment-mutations'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Setting options |
53
|
|
|
*/ |
54
|
|
|
public const OPTION_LIST_DEFAULT_LIMIT = 'list-default-limit'; |
55
|
|
|
public const OPTION_LIST_MAX_LIMIT = 'list-max-limit'; |
56
|
|
|
public const OPTION_ADD_TYPE_TO_CUSTOMPOST_UNION_TYPE = 'add-type-to-custompost-union-type'; |
57
|
|
|
public const OPTION_USE_SINGLE_TYPE_INSTEAD_OF_UNION_TYPE = 'use-single-type-instead-of-union-type'; |
58
|
|
|
public const OPTION_CUSTOMPOST_TYPES = 'custompost-types'; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Hooks |
62
|
|
|
*/ |
63
|
|
|
public const HOOK_GENERIC_CUSTOMPOST_TYPES = __CLASS__ . ':generic-custompost-types'; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string[] |
67
|
|
|
*/ |
68
|
|
|
public static function getModulesToResolve(): array |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
self::SCHEMA_CUSTOMPOSTS, |
72
|
|
|
self::SCHEMA_GENERIC_CUSTOMPOSTS, |
73
|
|
|
self::SCHEMA_POSTS, |
74
|
|
|
self::SCHEMA_PAGES, |
75
|
|
|
self::SCHEMA_USERS, |
76
|
|
|
self::SCHEMA_USER_ROLES, |
77
|
|
|
self::SCHEMA_COMMENTS, |
78
|
|
|
self::SCHEMA_TAGS, |
79
|
|
|
self::SCHEMA_POST_TAGS, |
80
|
|
|
self::SCHEMA_MEDIA, |
81
|
|
|
self::SCHEMA_USER_STATE_MUTATIONS, |
82
|
|
|
self::SCHEMA_CUSTOMPOST_MUTATIONS, |
83
|
|
|
self::SCHEMA_POST_MUTATIONS, |
84
|
|
|
self::SCHEMA_CUSTOMPOSTMEDIA_MUTATIONS, |
85
|
|
|
self::SCHEMA_COMMENT_MUTATIONS, |
86
|
|
|
]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return array<array> List of entries that must be satisfied, each entry is an array where at least 1 module must be satisfied |
91
|
|
|
*/ |
92
|
|
|
public function getDependedModuleLists(string $module): array |
93
|
|
|
{ |
94
|
|
|
switch ($module) { |
95
|
|
|
case self::SCHEMA_USERS: |
96
|
|
|
case self::SCHEMA_MEDIA: |
97
|
|
|
case self::SCHEMA_CUSTOMPOSTS: |
98
|
|
|
return [ |
99
|
|
|
[ |
100
|
|
|
EndpointFunctionalityModuleResolver::SINGLE_ENDPOINT, |
101
|
|
|
EndpointFunctionalityModuleResolver::PERSISTED_QUERIES, |
102
|
|
|
EndpointFunctionalityModuleResolver::CUSTOM_ENDPOINTS, |
103
|
|
|
], |
104
|
|
|
]; |
105
|
|
|
case self::SCHEMA_USER_ROLES: |
106
|
|
|
return [ |
107
|
|
|
[ |
108
|
|
|
self::SCHEMA_USERS, |
109
|
|
|
], |
110
|
|
|
]; |
111
|
|
|
case self::SCHEMA_GENERIC_CUSTOMPOSTS: |
112
|
|
|
case self::SCHEMA_POSTS: |
113
|
|
|
case self::SCHEMA_PAGES: |
114
|
|
|
case self::SCHEMA_COMMENTS: |
115
|
|
|
case self::SCHEMA_TAGS: |
116
|
|
|
return [ |
117
|
|
|
[ |
118
|
|
|
self::SCHEMA_CUSTOMPOSTS, |
119
|
|
|
], |
120
|
|
|
]; |
121
|
|
|
case self::SCHEMA_POST_TAGS: |
122
|
|
|
return [ |
123
|
|
|
[ |
124
|
|
|
self::SCHEMA_POSTS, |
125
|
|
|
], |
126
|
|
|
[ |
127
|
|
|
self::SCHEMA_TAGS, |
128
|
|
|
], |
129
|
|
|
]; |
130
|
|
|
case self::SCHEMA_USER_STATE_MUTATIONS: |
131
|
|
|
return [ |
132
|
|
|
[ |
133
|
|
|
OperationalFunctionalityModuleResolver::MUTATIONS, |
134
|
|
|
], |
135
|
|
|
]; |
136
|
|
|
case self::SCHEMA_CUSTOMPOST_MUTATIONS: |
137
|
|
|
return [ |
138
|
|
|
[ |
139
|
|
|
self::SCHEMA_USER_STATE_MUTATIONS, |
140
|
|
|
], |
141
|
|
|
[ |
142
|
|
|
self::SCHEMA_CUSTOMPOSTS, |
143
|
|
|
], |
144
|
|
|
]; |
145
|
|
|
case self::SCHEMA_POST_MUTATIONS: |
146
|
|
|
return [ |
147
|
|
|
[ |
148
|
|
|
self::SCHEMA_POSTS, |
149
|
|
|
], |
150
|
|
|
[ |
151
|
|
|
self::SCHEMA_CUSTOMPOST_MUTATIONS, |
152
|
|
|
], |
153
|
|
|
]; |
154
|
|
|
case self::SCHEMA_CUSTOMPOSTMEDIA_MUTATIONS: |
155
|
|
|
return [ |
156
|
|
|
[ |
157
|
|
|
self::SCHEMA_MEDIA, |
158
|
|
|
], |
159
|
|
|
[ |
160
|
|
|
self::SCHEMA_CUSTOMPOST_MUTATIONS, |
161
|
|
|
], |
162
|
|
|
]; |
163
|
|
|
case self::SCHEMA_COMMENT_MUTATIONS: |
164
|
|
|
return [ |
165
|
|
|
[ |
166
|
|
|
self::SCHEMA_USER_STATE_MUTATIONS, |
167
|
|
|
], |
168
|
|
|
[ |
169
|
|
|
self::SCHEMA_COMMENTS, |
170
|
|
|
], |
171
|
|
|
]; |
172
|
|
|
} |
173
|
|
|
return parent::getDependedModuleLists($module); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function getName(string $module): string |
177
|
|
|
{ |
178
|
|
|
$names = [ |
179
|
|
|
self::SCHEMA_GENERIC_CUSTOMPOSTS => \__('Schema Generic Custom Posts', 'graphql-api'), |
180
|
|
|
self::SCHEMA_POSTS => \__('Schema Posts', 'graphql-api'), |
181
|
|
|
self::SCHEMA_COMMENTS => \__('Schema Comments', 'graphql-api'), |
182
|
|
|
self::SCHEMA_USERS => \__('Schema Users', 'graphql-api'), |
183
|
|
|
self::SCHEMA_USER_ROLES => \__('Schema User Roles', 'graphql-api'), |
184
|
|
|
self::SCHEMA_PAGES => \__('Schema Pages', 'graphql-api'), |
185
|
|
|
self::SCHEMA_MEDIA => \__('Schema Media', 'graphql-api'), |
186
|
|
|
self::SCHEMA_TAGS => \__('Schema Tags', 'graphql-api'), |
187
|
|
|
self::SCHEMA_POST_TAGS => \__('Schema Post Tags', 'graphql-api'), |
188
|
|
|
self::SCHEMA_CUSTOMPOSTS => \__('Schema Custom Posts', 'graphql-api'), |
189
|
|
|
self::SCHEMA_USER_STATE_MUTATIONS => \__('Schema User State Mutations', 'graphql-api'), |
190
|
|
|
self::SCHEMA_CUSTOMPOST_MUTATIONS => \__('Schema Custom Post Mutations', 'graphql-api'), |
191
|
|
|
self::SCHEMA_POST_MUTATIONS => \__('Schema Post Mutations', 'graphql-api'), |
192
|
|
|
self::SCHEMA_CUSTOMPOSTMEDIA_MUTATIONS => \__('Schema Custom Post Media Mutations', 'graphql-api'), |
193
|
|
|
self::SCHEMA_COMMENT_MUTATIONS => \__('Schema Comment Mutations', 'graphql-api'), |
194
|
|
|
]; |
195
|
|
|
return $names[$module] ?? $module; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function getDescription(string $module): string |
199
|
|
|
{ |
200
|
|
|
switch ($module) { |
201
|
|
|
case self::SCHEMA_GENERIC_CUSTOMPOSTS: |
202
|
|
|
return sprintf( |
203
|
|
|
\__('Query any custom post type (added to the schema or not), through a generic type <code>%1$s</code>', 'graphql-api'), |
204
|
|
|
GenericCustomPostTypeResolver::NAME |
205
|
|
|
); |
206
|
|
|
case self::SCHEMA_POSTS: |
207
|
|
|
return sprintf( |
208
|
|
|
\__('Query %1$s, through type <code>%2$s</code> added to the schema', 'graphql-api'), |
209
|
|
|
\__('posts', 'graphql-api'), |
210
|
|
|
PostTypeResolver::NAME |
211
|
|
|
); |
212
|
|
|
case self::SCHEMA_USERS: |
213
|
|
|
return sprintf( |
214
|
|
|
\__('Query %1$s, through type <code>%2$s</code> added to the schema', 'graphql-api'), |
215
|
|
|
\__('users', 'graphql-api'), |
216
|
|
|
UserTypeResolver::NAME |
217
|
|
|
); |
218
|
|
|
case self::SCHEMA_USER_ROLES: |
219
|
|
|
return sprintf( |
220
|
|
|
\__('Query %1$s, through type <code>%2$s</code> added to the schema', 'graphql-api'), |
221
|
|
|
\__('user roles', 'graphql-api'), |
222
|
|
|
UserRoleTypeResolver::NAME |
223
|
|
|
); |
224
|
|
|
case self::SCHEMA_PAGES: |
225
|
|
|
return sprintf( |
226
|
|
|
\__('Query %1$s, through type <code>%2$s</code> added to the schema', 'graphql-api'), |
227
|
|
|
\__('pages', 'graphql-api'), |
228
|
|
|
PageTypeResolver::NAME |
229
|
|
|
); |
230
|
|
|
case self::SCHEMA_MEDIA: |
231
|
|
|
return sprintf( |
232
|
|
|
\__('Query %1$s, through type <code>%2$s</code> added to the schema', 'graphql-api'), |
233
|
|
|
\__('media elements', 'graphql-api'), |
234
|
|
|
MediaTypeResolver::NAME |
235
|
|
|
); |
236
|
|
|
case self::SCHEMA_COMMENTS: |
237
|
|
|
return sprintf( |
238
|
|
|
\__('Query %1$s, through type <code>%2$s</code> added to the schema', 'graphql-api'), |
239
|
|
|
\__('comments', 'graphql-api'), |
240
|
|
|
CommentTypeResolver::NAME |
241
|
|
|
); |
242
|
|
|
case self::SCHEMA_POST_TAGS: |
243
|
|
|
return sprintf( |
244
|
|
|
\__('Query %1$s, through type <code>%2$s</code> added to the schema', 'graphql-api'), |
245
|
|
|
\__('post tags', 'graphql-api'), |
246
|
|
|
PostTagTypeResolver::NAME |
247
|
|
|
); |
248
|
|
|
case self::SCHEMA_CUSTOMPOSTS: |
249
|
|
|
return \__('Base functionality for all custom posts', 'graphql-api'); |
250
|
|
|
case self::SCHEMA_TAGS: |
251
|
|
|
return \__('Base functionality for all tags', 'graphql-api'); |
252
|
|
|
case self::SCHEMA_USER_STATE_MUTATIONS: |
253
|
|
|
return \__('Have the user log-in, and be able to perform mutations', 'graphql-api'); |
254
|
|
|
case self::SCHEMA_CUSTOMPOST_MUTATIONS: |
255
|
|
|
return \__('Base functionality to mutate custom posts', 'graphql-api'); |
256
|
|
|
case self::SCHEMA_POST_MUTATIONS: |
257
|
|
|
return sprintf( |
258
|
|
|
\__('Execute mutations on %1$s', 'graphql-api'), |
259
|
|
|
\__('posts', 'graphql-api') |
260
|
|
|
); |
261
|
|
|
case self::SCHEMA_CUSTOMPOSTMEDIA_MUTATIONS: |
262
|
|
|
return \__('Execute mutations concerning media items on custom posts', 'graphql-api'); |
263
|
|
|
case self::SCHEMA_COMMENT_MUTATIONS: |
264
|
|
|
return \__('Create comments', 'graphql-api'); |
265
|
|
|
} |
266
|
|
|
return parent::getDescription($module); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Does the module have HTML Documentation? |
271
|
|
|
*/ |
272
|
|
|
public function hasDocumentation(string $module): bool |
273
|
|
|
{ |
274
|
|
|
switch ($module) { |
275
|
|
|
case self::SCHEMA_POSTS: |
276
|
|
|
case self::SCHEMA_PAGES: |
277
|
|
|
case self::SCHEMA_USERS: |
278
|
|
|
case self::SCHEMA_USER_ROLES: |
279
|
|
|
case self::SCHEMA_COMMENTS: |
280
|
|
|
case self::SCHEMA_TAGS: |
281
|
|
|
case self::SCHEMA_POST_TAGS: |
282
|
|
|
case self::SCHEMA_MEDIA: |
283
|
|
|
case self::SCHEMA_CUSTOMPOST_MUTATIONS: |
284
|
|
|
case self::SCHEMA_POST_MUTATIONS: |
285
|
|
|
case self::SCHEMA_CUSTOMPOSTMEDIA_MUTATIONS: |
286
|
|
|
case self::SCHEMA_COMMENT_MUTATIONS: |
287
|
|
|
return false; |
288
|
|
|
} |
289
|
|
|
return $this->upstreamHasDocumentation($module); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Indicate if the given value is valid for that option |
294
|
|
|
* |
295
|
|
|
* @param string $module |
296
|
|
|
* @param string $option |
297
|
|
|
* @param mixed $value |
298
|
|
|
* @return bool |
299
|
|
|
*/ |
300
|
|
|
public function isValidValue(string $module, string $option, $value): bool |
301
|
|
|
{ |
302
|
|
|
if ( |
303
|
|
|
in_array( |
304
|
|
|
$module, |
305
|
|
|
[ |
306
|
|
|
self::SCHEMA_CUSTOMPOSTS, |
307
|
|
|
// self::SCHEMA_GENERIC_CUSTOMPOSTS, |
308
|
|
|
// self::SCHEMA_POSTS, |
309
|
|
|
self::SCHEMA_USERS, |
310
|
|
|
self::SCHEMA_TAGS, |
311
|
|
|
// self::SCHEMA_PAGES, |
312
|
|
|
] |
313
|
|
|
) && in_array( |
314
|
|
|
$option, |
315
|
|
|
[ |
316
|
|
|
self::OPTION_LIST_DEFAULT_LIMIT, |
317
|
|
|
self::OPTION_LIST_MAX_LIMIT, |
318
|
|
|
] |
319
|
|
|
) |
320
|
|
|
) { |
321
|
|
|
// It can't be less than -1, or 0 |
322
|
|
|
if ($value < -1 or $value === 0) { |
323
|
|
|
return false; |
324
|
|
|
} |
325
|
|
|
} |
326
|
|
|
return parent::isValidValue($module, $option, $value); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Default value for an option set by the module |
331
|
|
|
* |
332
|
|
|
* @param string $module |
333
|
|
|
* @param string $option |
334
|
|
|
* @return mixed Anything the setting might be: an array|string|bool|int|null |
335
|
|
|
*/ |
336
|
|
|
public function getSettingsDefaultValue(string $module, string $option) |
337
|
|
|
{ |
338
|
|
|
$defaultValues = [ |
339
|
|
|
self::SCHEMA_CUSTOMPOSTS => [ |
340
|
|
|
self::OPTION_LIST_DEFAULT_LIMIT => 10, |
341
|
|
|
self::OPTION_LIST_MAX_LIMIT => 100, |
342
|
|
|
self::OPTION_USE_SINGLE_TYPE_INSTEAD_OF_UNION_TYPE => false, |
343
|
|
|
], |
344
|
|
|
self::SCHEMA_GENERIC_CUSTOMPOSTS => [ |
345
|
|
|
// self::OPTION_LIST_DEFAULT_LIMIT => 10, |
346
|
|
|
// self::OPTION_LIST_MAX_LIMIT => 100, |
347
|
|
|
self::OPTION_CUSTOMPOST_TYPES => ['post'], |
348
|
|
|
], |
349
|
|
|
self::SCHEMA_POSTS => [ |
350
|
|
|
// self::OPTION_LIST_DEFAULT_LIMIT => 10, |
351
|
|
|
// self::OPTION_LIST_MAX_LIMIT => 100, |
352
|
|
|
self::OPTION_ADD_TYPE_TO_CUSTOMPOST_UNION_TYPE => true, |
353
|
|
|
], |
354
|
|
|
self::SCHEMA_PAGES => [ |
355
|
|
|
// self::OPTION_LIST_DEFAULT_LIMIT => 10, |
356
|
|
|
// self::OPTION_LIST_MAX_LIMIT => 100, |
357
|
|
|
self::OPTION_ADD_TYPE_TO_CUSTOMPOST_UNION_TYPE => false, |
358
|
|
|
], |
359
|
|
|
self::SCHEMA_USERS => [ |
360
|
|
|
self::OPTION_LIST_DEFAULT_LIMIT => 10, |
361
|
|
|
self::OPTION_LIST_MAX_LIMIT => 100, |
362
|
|
|
], |
363
|
|
|
self::SCHEMA_TAGS => [ |
364
|
|
|
self::OPTION_LIST_DEFAULT_LIMIT => 20, |
365
|
|
|
self::OPTION_LIST_MAX_LIMIT => 200, |
366
|
|
|
], |
367
|
|
|
]; |
368
|
|
|
return $defaultValues[$module][$option]; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* Array with the inputs to show as settings for the module |
373
|
|
|
* |
374
|
|
|
* @return array<array> List of settings for the module, each entry is an array with property => value |
375
|
|
|
*/ |
376
|
|
|
public function getSettings(string $module): array |
377
|
|
|
{ |
378
|
|
|
$moduleSettings = parent::getSettings($module); |
379
|
|
|
// Common variables to set the limit on the schema types |
380
|
|
|
$limitArg = 'limit'; |
381
|
|
|
$unlimitedValue = -1; |
382
|
|
|
$defaultLimitMessagePlaceholder = \__('Number of results from querying %s when argument <code>%s</code> is not provided. Use <code>%s</code> for unlimited', 'graphql-api'); |
383
|
|
|
$maxLimitMessagePlaceholder = \__('Maximum number of results from querying %s. Use <code>%s</code> for unlimited', 'graphql-api'); |
384
|
|
|
// Do the if one by one, so that the SELECT do not get evaluated unless needed |
385
|
|
|
if ( |
386
|
|
|
in_array($module, [ |
387
|
|
|
self::SCHEMA_CUSTOMPOSTS, |
388
|
|
|
// self::SCHEMA_GENERIC_CUSTOMPOSTS, |
389
|
|
|
// self::SCHEMA_POSTS, |
390
|
|
|
self::SCHEMA_USERS, |
391
|
|
|
self::SCHEMA_TAGS, |
392
|
|
|
// self::SCHEMA_PAGES, |
393
|
|
|
]) |
394
|
|
|
) { |
395
|
|
|
$moduleEntries = [ |
396
|
|
|
self::SCHEMA_CUSTOMPOSTS => [ |
397
|
|
|
'entities' => \__('custom posts', 'graphql-api'), |
398
|
|
|
], |
399
|
|
|
// self::SCHEMA_GENERIC_CUSTOMPOSTS => [ |
400
|
|
|
// 'genericCustomPosts' => null, |
401
|
|
|
// ], |
402
|
|
|
// self::SCHEMA_POSTS => [ |
403
|
|
|
// 'posts' => null, |
404
|
|
|
// ], |
405
|
|
|
self::SCHEMA_USERS => [ |
406
|
|
|
'entities' => \__('users', 'graphql-api'), |
407
|
|
|
], |
408
|
|
|
self::SCHEMA_TAGS => [ |
409
|
|
|
'entities' => \__('tags', 'graphql-api'), |
410
|
|
|
], |
411
|
|
|
// self::SCHEMA_PAGES => [ |
412
|
|
|
// 'pages' => null, |
413
|
|
|
// ], |
414
|
|
|
]; |
415
|
|
|
$moduleEntry = $moduleEntries[$module]; |
416
|
|
|
// If the options is not provided, use the default one |
417
|
|
|
$entities = $moduleEntry['entities']; |
418
|
|
|
$options = $moduleEntry['options'] ?? [ |
419
|
|
|
self::OPTION_LIST_DEFAULT_LIMIT, |
420
|
|
|
self::OPTION_LIST_MAX_LIMIT, |
421
|
|
|
]; |
422
|
|
|
list( |
423
|
|
|
$defaultLimitOption, |
424
|
|
|
$maxLimitOption, |
425
|
|
|
) = $options; |
426
|
|
|
$moduleSettings[] = [ |
427
|
|
|
Properties::INPUT => $defaultLimitOption, |
428
|
|
|
Properties::NAME => $this->getSettingOptionName( |
429
|
|
|
$module, |
430
|
|
|
$defaultLimitOption |
431
|
|
|
), |
432
|
|
|
Properties::TITLE => sprintf( |
433
|
|
|
\__('Default limit for %s', 'graphql-api'), |
434
|
|
|
$entities |
435
|
|
|
), |
436
|
|
|
Properties::DESCRIPTION => sprintf( |
437
|
|
|
$defaultLimitMessagePlaceholder, |
438
|
|
|
$entities, |
439
|
|
|
$limitArg, |
440
|
|
|
$unlimitedValue |
441
|
|
|
), |
442
|
|
|
Properties::TYPE => Properties::TYPE_INT, |
443
|
|
|
Properties::MIN_NUMBER => -1, |
444
|
|
|
]; |
445
|
|
|
$moduleSettings[] = [ |
446
|
|
|
Properties::INPUT => $maxLimitOption, |
447
|
|
|
Properties::NAME => $this->getSettingOptionName( |
448
|
|
|
$module, |
449
|
|
|
$maxLimitOption |
450
|
|
|
), |
451
|
|
|
Properties::TITLE => sprintf( |
452
|
|
|
\__('Max limit for %s', 'graphql-api'), |
453
|
|
|
$entities |
454
|
|
|
), |
455
|
|
|
Properties::DESCRIPTION => sprintf( |
456
|
|
|
$maxLimitMessagePlaceholder, |
457
|
|
|
$entities, |
458
|
|
|
$unlimitedValue |
459
|
|
|
), |
460
|
|
|
Properties::TYPE => Properties::TYPE_INT, |
461
|
|
|
Properties::MIN_NUMBER => -1, |
462
|
|
|
]; |
463
|
|
|
|
464
|
|
|
if ($module == self::SCHEMA_CUSTOMPOSTS) { |
465
|
|
|
$option = self::OPTION_USE_SINGLE_TYPE_INSTEAD_OF_UNION_TYPE; |
466
|
|
|
$moduleSettings[] = [ |
467
|
|
|
Properties::INPUT => $option, |
468
|
|
|
Properties::NAME => $this->getSettingOptionName( |
469
|
|
|
$module, |
470
|
|
|
$option |
471
|
|
|
), |
472
|
|
|
Properties::TITLE => \__('Use single type instead of union type?', 'graphql-api'), |
473
|
|
|
Properties::DESCRIPTION => sprintf( |
474
|
|
|
\__('If type <code>%s</code> is composed of only one type (eg: <code>%s</code>), then return this single type directly in field <code>%s</code>?', 'graphql-api'), |
475
|
|
|
CustomPostUnionTypeResolver::NAME, |
476
|
|
|
PostTypeResolver::NAME, |
477
|
|
|
'customPosts' |
478
|
|
|
), |
479
|
|
|
Properties::TYPE => Properties::TYPE_BOOL, |
480
|
|
|
]; |
481
|
|
|
} |
482
|
|
|
} elseif ( |
483
|
|
|
in_array($module, [ |
484
|
|
|
self::SCHEMA_POSTS, |
485
|
|
|
self::SCHEMA_PAGES, |
486
|
|
|
]) |
487
|
|
|
) { |
488
|
|
|
$titlePlaceholder = sprintf( |
489
|
|
|
\__('Include type <code>%1$s</code> in <code>%2$s</code>?', 'graphql-api'), |
490
|
|
|
'%1$s', |
491
|
|
|
CustomPostUnionTypeResolver::NAME |
492
|
|
|
); |
493
|
|
|
$moduleTitles = [ |
494
|
|
|
self::SCHEMA_POSTS => sprintf( |
495
|
|
|
$titlePlaceholder, |
496
|
|
|
PostTypeResolver::NAME |
497
|
|
|
), |
498
|
|
|
self::SCHEMA_PAGES => sprintf( |
499
|
|
|
$titlePlaceholder, |
500
|
|
|
PageTypeResolver::NAME |
501
|
|
|
), |
502
|
|
|
]; |
503
|
|
|
$descriptionPlaceholder = sprintf( |
504
|
|
|
\__('Results of type <code>%1$s</code> will be included when querying a field of type <code>%2$s</code> (such as <code>%3$s</code>)', 'graphql-api'), |
505
|
|
|
'%1$s', |
506
|
|
|
CustomPostUnionTypeResolver::NAME, |
507
|
|
|
'customPosts' |
508
|
|
|
); |
509
|
|
|
$moduleDescriptions = [ |
510
|
|
|
self::SCHEMA_POSTS => sprintf( |
511
|
|
|
$descriptionPlaceholder, |
512
|
|
|
PostTypeResolver::NAME |
513
|
|
|
), |
514
|
|
|
self::SCHEMA_PAGES => sprintf( |
515
|
|
|
$descriptionPlaceholder, |
516
|
|
|
PageTypeResolver::NAME |
517
|
|
|
), |
518
|
|
|
]; |
519
|
|
|
$option = self::OPTION_ADD_TYPE_TO_CUSTOMPOST_UNION_TYPE; |
520
|
|
|
$moduleSettings[] = [ |
521
|
|
|
Properties::INPUT => $option, |
522
|
|
|
Properties::NAME => $this->getSettingOptionName( |
523
|
|
|
$module, |
524
|
|
|
$option |
525
|
|
|
), |
526
|
|
|
Properties::TITLE => $moduleTitles[$module], |
527
|
|
|
Properties::DESCRIPTION => $moduleDescriptions[$module], |
528
|
|
|
Properties::TYPE => Properties::TYPE_BOOL, |
529
|
|
|
]; |
530
|
|
|
} elseif ($module == self::SCHEMA_GENERIC_CUSTOMPOSTS) { |
531
|
|
|
// Get the list of custom post types from the system |
532
|
|
|
$genericCustomPostTypes = \get_post_types(); |
533
|
|
|
// Not all custom post types make sense or are allowed. |
534
|
|
|
// Remove the ones that do not |
535
|
|
|
$genericCustomPostTypes = array_values(array_diff( |
536
|
|
|
$genericCustomPostTypes, |
537
|
|
|
[ |
538
|
|
|
// Post Types from GraphQL API that contain private data |
539
|
|
|
GraphQLAccessControlListPostType::POST_TYPE, |
540
|
|
|
GraphQLCacheControlListPostType::POST_TYPE, |
541
|
|
|
GraphQLFieldDeprecationListPostType::POST_TYPE, |
542
|
|
|
GraphQLSchemaConfigurationPostType::POST_TYPE, |
543
|
|
|
GraphQLEndpointPostType::POST_TYPE, |
544
|
|
|
GraphQLPersistedQueryPostType::POST_TYPE, |
545
|
|
|
// WordPress internal CPTs |
546
|
|
|
// Attachment not allowed because its post_status="inherit", |
547
|
|
|
// not "publish", and the API filters by "publish" entries |
548
|
|
|
'attachment', |
549
|
|
|
'revision', |
550
|
|
|
'nav_menu_item', |
551
|
|
|
'custom_css', |
552
|
|
|
'customize_changeset', |
553
|
|
|
'oembed_cache', |
554
|
|
|
'user_request', |
555
|
|
|
'wp_block', |
556
|
|
|
'wp_area', |
557
|
|
|
] |
558
|
|
|
)); |
559
|
|
|
// Allow plugins to remove their own unwanted custom post types |
560
|
|
|
$genericCustomPostTypes = \apply_filters( |
561
|
|
|
self::HOOK_GENERIC_CUSTOMPOST_TYPES, |
562
|
|
|
$genericCustomPostTypes |
563
|
|
|
); |
564
|
|
|
// The possible values must have key and value |
565
|
|
|
$possibleValues = []; |
566
|
|
|
foreach ($genericCustomPostTypes as $genericCustomPostType) { |
567
|
|
|
$possibleValues[$genericCustomPostType] = $genericCustomPostType; |
568
|
|
|
} |
569
|
|
|
// Set the setting |
570
|
|
|
$option = self::OPTION_CUSTOMPOST_TYPES; |
571
|
|
|
$moduleSettings[] = [ |
572
|
|
|
Properties::INPUT => $option, |
573
|
|
|
Properties::NAME => $this->getSettingOptionName( |
574
|
|
|
$module, |
575
|
|
|
$option |
576
|
|
|
), |
577
|
|
|
Properties::TITLE => \__('Included custom post types', 'graphql-api'), |
578
|
|
|
Properties::DESCRIPTION => sprintf( |
579
|
|
|
\__('Results from these custom post types will be included when querying a field with type <code>%s</code> (such as <code>%s</code>)<br/>Press <code>ctrl</code> or <code>shift</code> keys to select more than one', 'graphql-api'), |
580
|
|
|
GenericCustomPostTypeResolver::NAME, |
581
|
|
|
'genericCustomPosts' |
582
|
|
|
), |
583
|
|
|
Properties::TYPE => Properties::TYPE_ARRAY, |
584
|
|
|
// Fetch all Schema Configurations from the DB |
585
|
|
|
Properties::POSSIBLE_VALUES => $possibleValues, |
586
|
|
|
Properties::IS_MULTIPLE => true, |
587
|
|
|
]; |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
return $moduleSettings; |
591
|
|
|
} |
592
|
|
|
} |
593
|
|
|
|