You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There could be cases when you want to include some custom fields into your GraphQL query and mutation operation. There are two ProcessWire hooks that allows you to do that.
150
150
151
-
#### getQuery() hook
151
+
#### getQueryFields() hook
152
152
153
153
You can hook into `getQuery` method of the `ProcessGraphQL` class to add some custom fields into your GraphQL query operation. Here how it could look like in your `graphql.php` template file.
154
154
@@ -159,14 +159,18 @@ use GraphQL\Type\Definition\Type;
wire()->addHookAfter('ProcessGraphQL::getQuery', function ($event) {
163
-
$query = $event->return;
164
-
$query->addField('hello', [
165
-
'type' => Type::string(),
166
-
'resolve' => function () {
167
-
return 'world!';
168
-
}
169
-
]);
162
+
wire()->addHookAfter("ProcessGraphQL::getQueryFields", function (
163
+
$event
164
+
) {
165
+
$fields = $event->return;
166
+
$fields[] = [
167
+
"name" => "hello",
168
+
"type" => Type::string(),
169
+
"resolve" => function () {
170
+
return "world!";
171
+
},
172
+
];
173
+
$event->return = $fields;
170
174
});
171
175
172
176
echo $processGraphQL->executeGraphQL();
@@ -176,7 +180,7 @@ The above code will add a `hello` field into your GraphQL api that reponds with
176
180
177
181
#### getMutation() hook
178
182
179
-
You can also hook into `getMutation` method of `ProcessGraphQL` class to add custom fields into your GraphQL mutation operation. It works exactly like the `getQuery` hook method.
183
+
You can also hook into `getMutationFields` method of `ProcessGraphQL` class to add custom fields into your GraphQL mutation operation. It works exactly like the `getQuery` hook method.
0 commit comments