Skip to content

Commit 857b359

Browse files
committed
Add some comments.
1 parent 53ee80b commit 857b359

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

ProcessGraphQL.module

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ProcessGraphQL extends Process implements Module {
1313
{
1414
return array(
1515
'title' => 'GraphQL',
16-
'version' => '0.11.0',
16+
'version' => '0.11.0',
1717
'summary' => 'GraphQL for ProcessWire.',
1818
'href' => 'https://github.com/dadish/ProcessGraphql',
1919
'singular' => true,
@@ -31,6 +31,13 @@ class ProcessGraphQL extends Process implements Module {
3131
$this->addHookAfter('Template::changed', $this, 'hookTemplateNameChange');
3232
}
3333

34+
/**
35+
* Updates the legalTemplates on name change. Template names for ProcessWire
36+
* are not necessarily valid for GraphQL field naming. Those names that are
37+
* not compatible are removed from legalFields, those that are compatible
38+
* are updated when changed.
39+
* @param HookEvent $event ProcessWire hook $event object.
40+
*/
3441
public function hookTemplateNameChange(HookEvent $event)
3542
{
3643
$whatChanged = $event->arguments[0];
@@ -59,19 +66,33 @@ class ProcessGraphQL extends Process implements Module {
5966
$this->modules->saveConfig($this, 'legalTemplates', $legalTemplates);
6067
}
6168

69+
/**
70+
* Returns the GraphiQL GUI for ProcessWire admin when request's header is not
71+
* set to AJAX. Executes GraphQL api if it is AJAX.
72+
* @return string The rendered string of either GraphiQL GUI or GraphQL json
73+
* response
74+
*/
6275
public function ___execute()
6376
{
6477
if ($this->config->ajax) return $this->executeGraphQL();
6578
return $this->executeGraphiQLPartial();
6679
}
6780

81+
/**
82+
* Returns a GraphiQL page.
83+
* @return string An HTML string.
84+
*/
6885
public function executeGraphiQL()
6986
{
7087
$this->setupGraphiQLAssets();
7188
$fullFilename = $this->config->paths->site . 'modules/ProcessGraphQL/GraphiQL/full.php';
7289
return wireRenderFile($fullFilename);
7390
}
7491

92+
/**
93+
* Returns only the necessary parts for the GraphiQL GUI.
94+
* @return string An HTML strin.
95+
*/
7596
public function executeGraphiQLPartial()
7697
{
7798
$this->setupGraphiQLAssets();
@@ -81,6 +102,9 @@ class ProcessGraphQL extends Process implements Module {
81102
]);
82103
}
83104

105+
/**
106+
* Setups the GraphiQL js/css assets for ProcessWire to handle in the admin.
107+
*/
84108
public function setupGraphiQLAssets()
85109
{
86110
$this->config->scripts->add($this->config->urls->ProcessGraphQL . 'GraphiQL/build/static/js/main.a8a92523.js');
@@ -90,13 +114,21 @@ class ProcessGraphQL extends Process implements Module {
90114
]);
91115
}
92116

117+
/**
118+
* Returns the server url from where the GraphiQL GUI will fetch the api.
119+
* @return string Url of the GraphQL server.
120+
*/
93121
public function getGraphQLServerUrl()
94122
{
95123
$url = $this->GraphQLServerUrl;
96124
if (!$url) $url = $this->pages->get('template=admin, name=' . self::pageName)->url;
97125
return $url;
98126
}
99127

128+
/**
129+
* Executes GraphQL api.
130+
* @return string GraphQL api JSON response.
131+
*/
100132
public function executeGraphQL()
101133
{
102134
// instantiating Processor and setting the schema
@@ -117,7 +149,6 @@ class ProcessGraphQL extends Process implements Module {
117149

118150
/**
119151
* Install the module page under setup
120-
*
121152
*/
122153
public function ___install()
123154
{
@@ -139,6 +170,9 @@ class ProcessGraphQL extends Process implements Module {
139170
$this->message("Created page at: {$page->path}");
140171
}
141172

173+
/**
174+
* Delete the module page
175+
*/
142176
public function ___uninstall()
143177
{
144178
// find page by process field

ProcessGraphQLConfig.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public function getDefaults()
3131
);
3232
}
3333

34+
/**
35+
* Checks if the given name is compatible with GraphQL.
36+
* @param string $name The name against the check will be performed.
37+
* @return boolean True if the name is compatible, false otherwise.
38+
*/
3439
public static function isLegalTemplateName($name)
3540
{
3641
if (!$name) return false;
@@ -41,6 +46,10 @@ public static function isLegalTemplateName($name)
4146
return true;
4247
}
4348

49+
/**
50+
* Build module configuration.
51+
* @return InputFields ProcessWire Inputfields form.
52+
*/
4453
public function getInputFields()
4554
{
4655
$inputfields = parent::getInputFields();

0 commit comments

Comments
 (0)