Skip to content

Commit f12a636

Browse files
committed
Add support for getQuery & getMutation hooks.
1 parent 5319c87 commit f12a636

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

ProcessGraphQL.module

+28
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,34 @@ class ProcessGraphQL extends Process implements Module {
151151
return json_encode($response);
152152
}
153153

154+
/**
155+
* The hook for modifying the GraphQL query operation by the user.
156+
* The query operation could be modified with addField/addFields methods.
157+
* See the documentation of the library used by this module to learn more
158+
* @see The GraphQL lib https://github.com/Youshido/GraphQL
159+
* @param $query The $query object that will be modified.
160+
* @return The $query object to modify. Do not replace the returned value,
161+
* but modify it with addField/addFields methods
162+
*/
163+
public function ___getQuery($query)
164+
{
165+
return $query;
166+
}
167+
168+
/**
169+
* The hook for modifying the GraphQL mutation operation by the user.
170+
* The mutation operation could be modified with addField/addFields methods.
171+
* See the documentation of the library used by this module to learn more
172+
* @see The GraphQL lib https://github.com/Youshido/GraphQL
173+
* @param * $mutation The $mutation object that will be modified.
174+
* @return * The $mutation object to modify. The same thing as the
175+
* $query argument.
176+
*/
177+
public function ___getMutation($mutation)
178+
{
179+
return $mutation;
180+
}
181+
154182
/**
155183
* Install the module page under setup
156184
*/

src/Schema.php

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function build(SchemaConfig $config)
2626
*/
2727
$query = $config->getQuery();
2828

29+
2930
// $pages API
3031
if ($moduleConfig->pagesQuery) {
3132
$query->addField(new PagesField());
@@ -60,6 +61,9 @@ public function build(SchemaConfig $config)
6061
$query->addField(new LanguageField());
6162
}
6263

64+
// let the user modify the query operation
65+
Utils::module()->getQuery($query);
66+
6367
/**
6468
* Mutation
6569
*/
@@ -75,6 +79,9 @@ public function build(SchemaConfig $config)
7579
$mutation->addField(new UpdateTemplatedPage($template));
7680
}
7781

82+
// let the user modify the mutation operation
83+
Utils::module()->getMutation($mutation);
84+
7885
}
7986

8087
public function getName()

0 commit comments

Comments
 (0)