Skip to content

Commit 83cab1c

Browse files
committed
Update docs for hooks
1 parent fb6a2c1 commit 83cab1c

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

Readme.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ echo $ProcessGraphQL->executeGraphiQL();
148148

149149
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.
150150

151-
#### getQuery() hook
151+
#### getQueryFields() hook
152152

153153
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.
154154

@@ -159,14 +159,18 @@ use GraphQL\Type\Definition\Type;
159159

160160
$processGraphQL = $modules->get('ProcessGraphQL');
161161

162-
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;
170174
});
171175

172176
echo $processGraphQL->executeGraphQL();
@@ -176,7 +180,7 @@ The above code will add a `hello` field into your GraphQL api that reponds with
176180

177181
#### getMutation() hook
178182

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.
180184

181185
## Features
182186

0 commit comments

Comments
 (0)