Skip to content

Commit 39eed70

Browse files
committed
code review on graphql entrypoint
1 parent c8a36a9 commit 39eed70

File tree

11 files changed

+369
-156
lines changed

11 files changed

+369
-156
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/**
4+
* SiteBase
5+
* PHP Version 8.3
6+
*
7+
* @category CMS / Framework
8+
* @package Degami\Sitebase
9+
* @author Mirko De Grandis <degami@github.com>
10+
* @license MIT https://opensource.org/licenses/mit-license.php
11+
* @link https://github.com/degami/sitebase
12+
*/
13+
14+
namespace App\Base\EventListeners\GraphQL;
15+
16+
use App\Base\Interfaces\EventListenerInterface;
17+
use Gplanchat\EventManager\Event;
18+
use GraphQL\Type\Definition\Type;
19+
use GraphQL\Type\Definition\ObjectType;
20+
21+
class ConfigurationEventListener implements EventListenerInterface
22+
{
23+
public function getEventHandlers() : array
24+
{
25+
// Return an array of event handlers as required by the interface
26+
return [
27+
'register_graphql_query_fields' => [$this, 'RegisterGraphQLQueryFields']
28+
];
29+
}
30+
31+
public function RegisterGraphQLQueryFields(Event $e)
32+
{
33+
$object = $e->getData('object');
34+
$queryFields = &$object->queryFields;
35+
$typesByName = &$object->typesByName;
36+
$typesByClass = &$object->typesByClass;
37+
38+
if (!isset($typesByName['ConfigEntry'])) {
39+
$typesByName['ConfigEntry'] = new ObjectType([
40+
'name' => 'ConfigEntry',
41+
'fields' => [
42+
'path' => ['type' => Type::nonNull(Type::string())],
43+
'value' => ['type' => Type::string()],
44+
]
45+
]);
46+
}
47+
48+
if (!isset($typesByName['ConfigsResult'])) {
49+
$typesByName['ConfigsResult'] = new ObjectType([
50+
'name' => 'ConfigsResult',
51+
'fields' => [
52+
'website' => ['type' => Type::nonNull($typesByName['Website'])],
53+
'locale' => ['type' => Type::string()],
54+
'configs' => ['type' => Type::listOf($typesByName['ConfigEntry'])],
55+
]
56+
]);
57+
}
58+
59+
if (!isset($queryFields['translations'])) {
60+
// configuration: [ConfigsResult]
61+
$queryFields['configuration'] = [
62+
'type' => Type::listOf($typesByName['ConfigsResult']),
63+
];
64+
}
65+
}
66+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/**
4+
* SiteBase
5+
* PHP Version 8.3
6+
*
7+
* @category CMS / Framework
8+
* @package Degami\Sitebase
9+
* @author Mirko De Grandis <degami@github.com>
10+
* @license MIT https://opensource.org/licenses/mit-license.php
11+
* @link https://github.com/degami/sitebase
12+
*/
13+
14+
namespace App\Base\EventListeners\GraphQL;
15+
16+
use App\Base\Interfaces\EventListenerInterface;
17+
use Gplanchat\EventManager\Event;
18+
use GraphQL\Type\Definition\Type;
19+
20+
class MenuTreeEventListener implements EventListenerInterface
21+
{
22+
public function getEventHandlers() : array
23+
{
24+
// Return an array of event handlers as required by the interface
25+
return [
26+
'register_graphql_query_fields' => [$this, 'RegisterGraphQLQueryFields']
27+
];
28+
}
29+
30+
public function RegisterGraphQLQueryFields(Event $e)
31+
{
32+
$object = $e->getData('object');
33+
$queryFields = &$object->queryFields;
34+
$typesByName = &$object->typesByName;
35+
$typesByClass = &$object->typesByClass;
36+
37+
if (!isset($typesByName['menuTree'])) {
38+
// menuTree(menu_name: String!, website_id: Int!): [Menu]
39+
$queryFields['menuTree'] = [
40+
'args' => [
41+
'menu_name' => ['type' => Type::nonNull(Type::string())],
42+
'website_id' => ['type' => Type::nonNull(Type::int())]
43+
],
44+
'type' => Type::listOf($typesByName['Menu']),
45+
];
46+
}
47+
}
48+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/**
4+
* SiteBase
5+
* PHP Version 8.3
6+
*
7+
* @category CMS / Framework
8+
* @package Degami\Sitebase
9+
* @author Mirko De Grandis <degami@github.com>
10+
* @license MIT https://opensource.org/licenses/mit-license.php
11+
* @link https://github.com/degami/sitebase
12+
*/
13+
14+
namespace App\Base\EventListeners\GraphQL;
15+
16+
use App\Base\Interfaces\EventListenerInterface;
17+
use Gplanchat\EventManager\Event;
18+
use GraphQL\Type\Definition\Type;
19+
use GraphQL\Type\Definition\ObjectType;
20+
21+
class PageRegionsEventListener implements EventListenerInterface
22+
{
23+
public function getEventHandlers() : array
24+
{
25+
// Return an array of event handlers as required by the interface
26+
return [
27+
'register_graphql_query_fields' => [$this, 'RegisterGraphQLQueryFields']
28+
];
29+
}
30+
31+
public function RegisterGraphQLQueryFields(Event $e)
32+
{
33+
$object = $e->getData('object');
34+
$queryFields = &$object->queryFields;
35+
$typesByName = &$object->typesByName;
36+
$typesByClass = &$object->typesByClass;
37+
38+
39+
if (!isset($typesByName['PageRegions'])) {
40+
$typesByName['PageRegions'] = new ObjectType([
41+
'name' => 'PageRegions',
42+
'fields' => [
43+
'after_body_open' => ['type' => Type::string()],
44+
'before_body_close' => ['type' => Type::string()],
45+
'pre_menu' => ['type' => Type::string()],
46+
'post_menu' => ['type' => Type::string()],
47+
'pre_header' => ['type' => Type::string()],
48+
'post_header' => ['type' => Type::string()],
49+
'pre_content' => ['type' => Type::string()],
50+
'post_content' => ['type' => Type::string()],
51+
'pre_footer' => ['type' => Type::string()],
52+
'post_footer' => ['type' => Type::string()],
53+
]
54+
]);
55+
}
56+
57+
if (!isset($typesByName['PageRegionsResponse'])) {
58+
$typesByName['PageRegionsResponse'] = new ObjectType([
59+
'name' => 'PageRegionsResponse',
60+
'fields' => [
61+
'locale' => ['type' => Type::string()],
62+
'regions' => ['type' => $typesByName['PageRegions']],
63+
]
64+
]);
65+
}
66+
67+
if (!isset($queryFields['translations'])) {
68+
// pageRegions(rewrite_id: Int, route_path: String): PageRegionsResponse
69+
$queryFields['pageRegions'] = [
70+
'type' => $typesByName['PageRegionsResponse'],
71+
'args' => [
72+
'rewrite_id' => ['type' => Type::int()],
73+
'route_path' => ['type' => Type::string()],
74+
],
75+
];
76+
}
77+
}
78+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/**
4+
* SiteBase
5+
* PHP Version 8.3
6+
*
7+
* @category CMS / Framework
8+
* @package Degami\Sitebase
9+
* @author Mirko De Grandis <degami@github.com>
10+
* @license MIT https://opensource.org/licenses/mit-license.php
11+
* @link https://github.com/degami/sitebase
12+
*/
13+
14+
namespace App\Base\EventListeners\GraphQL;
15+
16+
use App\Base\Interfaces\EventListenerInterface;
17+
use Gplanchat\EventManager\Event;
18+
use GraphQL\Type\Definition\Type;
19+
use GraphQL\Type\Definition\ObjectType;
20+
21+
class SearchEventListener implements EventListenerInterface
22+
{
23+
public function getEventHandlers() : array
24+
{
25+
// Return an array of event handlers as required by the interface
26+
return [
27+
'register_graphql_query_fields' => [$this, 'RegisterGraphQLQueryFields']
28+
];
29+
}
30+
31+
public function RegisterGraphQLQueryFields(Event $e)
32+
{
33+
$object = $e->getData('object');
34+
$queryFields = &$object->queryFields;
35+
$typesByName = &$object->typesByName;
36+
$typesByClass = &$object->typesByClass;
37+
38+
if (!isset($typesByName['ResultItem'])) {
39+
$typesByName['ResultItem'] = new ObjectType([
40+
'name' => 'ResultItem',
41+
'fields' => [
42+
'frontend_url' => ['type' => Type::nonNull(Type::string())],
43+
'title' => ['type' => Type::nonNull(Type::string())],
44+
'excerpt' => ['type' => Type::nonNull(Type::string())],
45+
]
46+
]);
47+
}
48+
49+
if (!isset($typesByName['SearchResult'])) {
50+
$typesByName['SearchResult'] = new ObjectType([
51+
'name' => 'SearchResult',
52+
'fields' => [
53+
'search_query' => ['type' => Type::nonNull(Type::string())],
54+
'search_result' => ['type' => Type::listOf($typesByName['ResultItem'])],
55+
'total' => ['type' => Type::nonNull(Type::int())],
56+
'page' => ['type' => Type::nonNull(Type::int())],
57+
]
58+
]);
59+
}
60+
61+
if (!isset($queryFields['search'])) {
62+
// search(input: String!, locale: String, page: Int): SearchResult
63+
$queryFields['search'] = [
64+
'type' => $typesByName['SearchResult'],
65+
'args' => [
66+
'input' => ['type' => Type::nonNull(Type::string())],
67+
'locale' => ['type' => Type::string()],
68+
'page' => ['type' => Type::int()],
69+
],
70+
];
71+
}
72+
}
73+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/**
4+
* SiteBase
5+
* PHP Version 8.3
6+
*
7+
* @category CMS / Framework
8+
* @package Degami\Sitebase
9+
* @author Mirko De Grandis <degami@github.com>
10+
* @license MIT https://opensource.org/licenses/mit-license.php
11+
* @link https://github.com/degami/sitebase
12+
*/
13+
14+
namespace App\Base\EventListeners\GraphQL;
15+
16+
use App\Base\Interfaces\EventListenerInterface;
17+
use Gplanchat\EventManager\Event;
18+
use GraphQL\Type\Definition\Type;
19+
use GraphQL\Type\Definition\ObjectType;
20+
21+
class TranslationsEventListener implements EventListenerInterface
22+
{
23+
public function getEventHandlers() : array
24+
{
25+
// Return an array of event handlers as required by the interface
26+
return [
27+
'register_graphql_query_fields' => [$this, 'RegisterGraphQLQueryFields']
28+
];
29+
}
30+
31+
public function RegisterGraphQLQueryFields(Event $e)
32+
{
33+
$object = $e->getData('object');
34+
$queryFields = &$object->queryFields;
35+
$typesByName = &$object->typesByName;
36+
$typesByClass = &$object->typesByClass;
37+
38+
if (!isset($this->typesByName['TranslationEntry'])) {
39+
$typesByName['TranslationEntry'] = new ObjectType([
40+
'name' => 'TranslationEntry',
41+
'fields' => [
42+
'key' => ['type' => Type::nonNull(Type::string())],
43+
'value' => ['type' => Type::nonNull(Type::string())],
44+
]
45+
]);
46+
}
47+
48+
if (!isset($queryFields['translations'])) {
49+
// translations: [TranslationEntry],
50+
$queryFields['translations'] = [
51+
'type' => Type::listOf($typesByName['TranslationEntry']),
52+
];
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)