1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GraphQLAPI\GraphQLAPI\ModuleResolvers; |
6
|
|
|
|
7
|
|
|
use GraphQLAPI\GraphQLAPI\Plugin; |
8
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleResolvers\ModuleResolverTrait; |
9
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleTypeResolvers\ModuleTypeResolver; |
10
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleSettings\Properties; |
11
|
|
|
|
12
|
|
|
class OperationalFunctionalityModuleResolver extends AbstractFunctionalityModuleResolver |
13
|
|
|
{ |
14
|
|
|
use ModuleResolverTrait; |
15
|
|
|
|
16
|
|
|
public const MULTIPLE_QUERY_EXECUTION = Plugin::NAMESPACE . '\multiple-query-execution'; |
17
|
|
|
public const REMOVE_IF_NULL_DIRECTIVE = Plugin::NAMESPACE . '\remove-if-null-directive'; |
18
|
|
|
public const PROACTIVE_FEEDBACK = Plugin::NAMESPACE . '\proactive-feedback'; |
19
|
|
|
public const EMBEDDABLE_FIELDS = Plugin::NAMESPACE . '\embeddable-fields'; |
20
|
|
|
public const MUTATIONS = Plugin::NAMESPACE . '\mutations'; |
21
|
|
|
public const NESTED_MUTATIONS = Plugin::NAMESPACE . '\nested-mutations'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Setting options |
25
|
|
|
*/ |
26
|
|
|
public const OPTION_DISABLE_REDUNDANT_MUTATION_FIELDS_IN_ROOT_TYPE = 'disable-redundant-mutation-fields-in-root-type'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return string[] |
30
|
|
|
*/ |
31
|
|
|
public static function getModulesToResolve(): array |
32
|
|
|
{ |
33
|
|
|
return [ |
34
|
|
|
self::MULTIPLE_QUERY_EXECUTION, |
35
|
|
|
self::REMOVE_IF_NULL_DIRECTIVE, |
36
|
|
|
self::PROACTIVE_FEEDBACK, |
37
|
|
|
self::EMBEDDABLE_FIELDS, |
38
|
|
|
self::MUTATIONS, |
39
|
|
|
self::NESTED_MUTATIONS, |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Enable to customize a specific UI for the module |
45
|
|
|
*/ |
46
|
|
|
public function getModuleType(string $module): string |
47
|
|
|
{ |
48
|
|
|
return ModuleTypeResolver::OPERATIONAL; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return array<array> List of entries that must be satisfied, each entry is an array where at least 1 module must be satisfied |
53
|
|
|
*/ |
54
|
|
|
public function getDependedModuleLists(string $module): array |
55
|
|
|
{ |
56
|
|
|
switch ($module) { |
57
|
|
|
case self::MULTIPLE_QUERY_EXECUTION: |
58
|
|
|
return [ |
59
|
|
|
[ |
60
|
|
|
EndpointFunctionalityModuleResolver::PERSISTED_QUERIES, |
61
|
|
|
EndpointFunctionalityModuleResolver::SINGLE_ENDPOINT, |
62
|
|
|
EndpointFunctionalityModuleResolver::CUSTOM_ENDPOINTS, |
63
|
|
|
], |
64
|
|
|
]; |
65
|
|
|
case self::REMOVE_IF_NULL_DIRECTIVE: |
66
|
|
|
case self::PROACTIVE_FEEDBACK: |
67
|
|
|
case self::EMBEDDABLE_FIELDS: |
68
|
|
|
case self::MUTATIONS: |
69
|
|
|
return []; |
70
|
|
|
case self::NESTED_MUTATIONS: |
71
|
|
|
return [ |
72
|
|
|
[ |
73
|
|
|
self::MUTATIONS, |
74
|
|
|
] |
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
return parent::getDependedModuleLists($module); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getName(string $module): string |
81
|
|
|
{ |
82
|
|
|
$names = [ |
83
|
|
|
self::MULTIPLE_QUERY_EXECUTION => \__('Multiple Query Execution', 'graphql-api'), |
84
|
|
|
self::REMOVE_IF_NULL_DIRECTIVE => \__('Remove if Null', 'graphql-api'), |
85
|
|
|
self::PROACTIVE_FEEDBACK => \__('Proactive Feedback', 'graphql-api'), |
86
|
|
|
self::EMBEDDABLE_FIELDS => \__('Embeddable Fields', 'graphql-api'), |
87
|
|
|
self::MUTATIONS => \__('Mutations', 'graphql-api'), |
88
|
|
|
self::NESTED_MUTATIONS => \__('Nested Mutations', 'graphql-api'), |
89
|
|
|
]; |
90
|
|
|
return $names[$module] ?? $module; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getDescription(string $module): string |
94
|
|
|
{ |
95
|
|
|
switch ($module) { |
96
|
|
|
case self::MULTIPLE_QUERY_EXECUTION: |
97
|
|
|
return \__('Execute multiple GraphQL queries in a single operation', 'graphql-api'); |
98
|
|
|
case self::REMOVE_IF_NULL_DIRECTIVE: |
99
|
|
|
return \__('Addition of <code>@removeIfNull</code> directive, to remove an output from the response if it is <code>null</code>', 'graphql-api'); |
100
|
|
|
case self::PROACTIVE_FEEDBACK: |
101
|
|
|
return \__('Usage of the top-level entry <code>extensions</code> to send deprecations, warnings, logs, notices and traces in the response to the query', 'graphql-api'); |
102
|
|
|
case self::EMBEDDABLE_FIELDS: |
103
|
|
|
return \__('Embed the value of field into the argument of another field, via notation <code>{{ field }}</code>', 'graphql-api'); |
104
|
|
|
case self::MUTATIONS: |
105
|
|
|
return \__('Modify data by executing mutations', 'graphql-api'); |
106
|
|
|
case self::NESTED_MUTATIONS: |
107
|
|
|
return \__('Execute mutations from any type in the schema, not only from the root', 'graphql-api'); |
108
|
|
|
} |
109
|
|
|
return parent::getDescription($module); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function isEnabledByDefault(string $module): bool |
113
|
|
|
{ |
114
|
|
|
switch ($module) { |
115
|
|
|
case self::MULTIPLE_QUERY_EXECUTION: |
116
|
|
|
case self::REMOVE_IF_NULL_DIRECTIVE: |
117
|
|
|
case self::EMBEDDABLE_FIELDS: |
118
|
|
|
case self::NESTED_MUTATIONS: |
119
|
|
|
return false; |
120
|
|
|
} |
121
|
|
|
return parent::isEnabledByDefault($module); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Default value for an option set by the module |
126
|
|
|
* |
127
|
|
|
* @param string $module |
128
|
|
|
* @param string $option |
129
|
|
|
* @return mixed Anything the setting might be: an array|string|bool|int|null |
130
|
|
|
*/ |
131
|
|
|
public function getSettingsDefaultValue(string $module, string $option) |
132
|
|
|
{ |
133
|
|
|
$defaultValues = [ |
134
|
|
|
self::NESTED_MUTATIONS => [ |
135
|
|
|
self::OPTION_DISABLE_REDUNDANT_MUTATION_FIELDS_IN_ROOT_TYPE => false, |
136
|
|
|
], |
137
|
|
|
]; |
138
|
|
|
return $defaultValues[$module][$option]; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Array with the inputs to show as settings for the module |
143
|
|
|
* |
144
|
|
|
* @return array<array> List of settings for the module, each entry is an array with property => value |
145
|
|
|
*/ |
146
|
|
|
public function getSettings(string $module): array |
147
|
|
|
{ |
148
|
|
|
$moduleSettings = parent::getSettings($module); |
149
|
|
|
// Do the if one by one, so that the SELECT do not get evaluated unless needed |
150
|
|
|
if ($module == self::NESTED_MUTATIONS) { |
151
|
|
|
$option = self::OPTION_DISABLE_REDUNDANT_MUTATION_FIELDS_IN_ROOT_TYPE; |
152
|
|
|
$moduleSettings[] = [ |
153
|
|
|
Properties::INPUT => $option, |
154
|
|
|
Properties::NAME => $this->getSettingOptionName( |
155
|
|
|
$module, |
156
|
|
|
$option |
157
|
|
|
), |
158
|
|
|
Properties::TITLE => \__('Disable redundant mutation fields in the root type?', 'graphql-api'), |
159
|
|
|
Properties::DESCRIPTION => \__('With nested mutations, operations can be executed on an entity type, and the equivalent operation in the root type can be considered redundant, and removed from the schema. For instance, field <code>Root.updatePost</code> can be removed when <code>Post.update</code> is available', 'graphql-api'), |
160
|
|
|
Properties::TYPE => Properties::TYPE_BOOL, |
161
|
|
|
]; |
162
|
|
|
} |
163
|
|
|
return $moduleSettings; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|