Skip to content

Commit 46de10a

Browse files
committed
updated namespace convention to allow ExtendType
1 parent 6e624aa commit 46de10a

33 files changed

+130
-100
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ The addon provides the following queries:
4949

5050
Before creating your own queries and mutations, you need to create your own
5151
types. You can do this by creating a class that uses a namespace that starts
52-
with `GraphQL\Type`. After that, you need to annotate with the `#[Type]`
52+
with `RexGraphQL\Type`. After that, you need to annotate with the `#[Type]`
5353
annotation.
5454
For example:
5555

5656
```php
5757
<?php
5858

59-
namespace GraphQL\Type\MyType;
59+
namespace RexGraphQL\Type\MyType;
6060

6161
use TheCodingMachine\GraphQLite\Annotations\Type;
6262

@@ -73,7 +73,7 @@ getter methods with the `#[Field]` annotation. For example:
7373
```php
7474
<?php
7575

76-
namespace GraphQL\Type;
76+
namespace RexGraphQL\Type;
7777

7878
use TheCodingMachine\GraphQLite\Annotations\Field;
7979
use TheCodingMachine\GraphQLite\Annotations\Type;
@@ -102,7 +102,7 @@ example:
102102
```php
103103
<?php
104104

105-
namespace GraphQL\Controller;
105+
namespace RexGraphQL\Controller;
106106

107107
use TheCodingMachine\GraphQLite\Annotations\Mutation;
108108
use TheCodingMachine\GraphQLite\Annotations\Query;
@@ -138,9 +138,9 @@ array. For example, if the return type is `string[]`, the GraphQL type will be
138138
```php
139139
<?php
140140

141-
namespace GraphQL\Controller;
141+
namespace RexGraphQL\Controller;
142142

143-
use GraphQL\Type\MyType;
143+
use RexGraphQL\Type\MyType;
144144
use TheCodingMachine\GraphQLite\Annotations\Mutation;
145145
use TheCodingMachine\GraphQLite\Annotations\Query;
146146

@@ -183,9 +183,9 @@ Queries and mutations can also have parameters. For example:
183183
```php
184184
<?php
185185

186-
namespace GraphQL\Controller;
186+
namespace RexGraphQL\Controller;
187187

188-
use GraphQL\Type\MyType;
188+
use RexGraphQL\Type\MyType;
189189
use TheCodingMachine\GraphQLite\Annotations\Mutation;
190190
use TheCodingMachine\GraphQLite\Annotations\Query;
191191

lib/Controller/ArticleController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace GraphQL\Controller;
3+
namespace RexGraphQL\Controller;
44

5-
use GraphQL\Type\Structure\Article;
5+
use RexGraphQL\Type\Structure\Article;
66
use GraphQL\Service\Structure\ArticleService;
77
use TheCodingMachine\GraphQLite\Annotations\Query;
88
use TheCodingMachine\GraphQLite\Types\ID;

lib/Controller/ArticleSliceController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace GraphQL\Controller;
3+
namespace RexGraphQL\Controller;
44

5-
use GraphQL\Type\Structure\ArticleSlice;
5+
use RexGraphQL\Type\Structure\ArticleSlice;
66
use GraphQL\Service\Structure\ArticleSliceService;
77
use TheCodingMachine\GraphQLite\Annotations\Query;
88
use TheCodingMachine\GraphQLite\Types\ID;

lib/Controller/CategoryController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace GraphQL\Controller;
3+
namespace RexGraphQL\Controller;
44

5-
use GraphQL\Type\Structure\Category;
5+
use RexGraphQL\Type\Structure\Category;
66
use GraphQL\Service\Structure\CategoryService;
77
use TheCodingMachine\GraphQLite\Annotations\Query;
88

lib/Controller/ClangController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace GraphQL\Controller;
3+
namespace RexGraphQL\Controller;
44

5-
use GraphQL\Type\Structure\Clang;
5+
use RexGraphQL\Type\Structure\Clang;
66
use GraphQL\Service\Structure\ClangService;
77
use TheCodingMachine\GraphQLite\Annotations\Query;
88
use TheCodingMachine\GraphQLite\Types\ID;

lib/Controller/ContentTypeController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace GraphQL\Controller;
3+
namespace RexGraphQL\Controller;
44

55
use GraphQL\Service\Structure\ContentTypeService;
6-
use GraphQL\Type\Structure\ContentType;
6+
use RexGraphQL\Type\Structure\ContentType;
77
use TheCodingMachine\GraphQLite\Annotations\Query;
88

99
class ContentTypeController

lib/Controller/MediaController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace GraphQL\Controller;
3+
namespace RexGraphQL\Controller;
44

5-
use GraphQL\Type\Media\Media;
5+
use RexGraphQL\Type\Media\Media;
66
use GraphQL\Service\Media\MediaService;
77
use TheCodingMachine\GraphQLite\Annotations\Query;
88

lib/Controller/NavigationController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace GraphQL\Controller;
3+
namespace RexGraphQL\Controller;
44

55
use GraphQL\Service\Navigation\NavigationService;
6-
use GraphQL\Type\Navigation\NavigationItem;
6+
use RexGraphQL\Type\Navigation\NavigationItem;
77
use TheCodingMachine\GraphQLite\Annotations\Query;
88
use TheCodingMachine\GraphQLite\Types\ID;
99

lib/Controller/SprogController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace GraphQL\Controller;
3+
namespace RexGraphQL\Controller;
44

5-
use GraphQL\Type\Sprog\WildCard;
5+
use RexGraphQL\Type\Sprog\WildCard;
66
use GraphQL\Service\Sprog\WildCardService;
77
use TheCodingMachine\GraphQLite\Annotations\Query;
88

lib/Endpoint.php

+22-18
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@
33
namespace GraphQL;
44

55
use GraphQL\Error\DebugFlag;
6-
use GraphQL\Type\SchemaConfig;
7-
use GraphQL\TypeMapper\RexQueryProviderFactory;
8-
use GraphQL\TypeMapper\RexTypeMapperFactory;
6+
use rex;
7+
use rex_extension;
8+
use rex_extension_point;
9+
use rex_response;
10+
use rex_var;
911
use Symfony\Component\DependencyInjection\Container;
1012
use TheCodingMachine\GraphQLite\Context\Context;
1113
use TheCodingMachine\GraphQLite\Exceptions\WebonyxErrorHandler;
1214
use TheCodingMachine\GraphQLite\Schema;
1315
use TheCodingMachine\GraphQLite\SchemaFactory;
1416
use Yiisoft\Cache\ArrayCache;
1517

18+
use function is_array;
19+
1620
class Endpoint
1721
{
1822
private SchemaFactory $schemaFactory;
1923

2024
public function __construct()
2125
{
2226
$this->schemaFactory = new SchemaFactory(
23-
new ArrayCache(), new Container()
27+
new ArrayCache(), new Container(),
2428
);
2529
}
2630

@@ -34,16 +38,16 @@ public function executeQuery(): array
3438
$input['query'],
3539
null,
3640
new Context(),
37-
$input['variables'] ?? null
41+
$input['variables'] ?? null,
3842
)->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter'])
3943
->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler'])
4044
->toArray(self::isDebug() ? DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE : DebugFlag::NONE);
4145
}
4246

4347
private function generateSchema(): Schema
4448
{
45-
$this->schemaFactory->addTypeMapperFactory(new RexTypeMapperFactory());
46-
$this->schemaFactory->addQueryProviderFactory(new RexQueryProviderFactory());
49+
$this->schemaFactory->addQueryProviderFactory(new \GraphQL\RexQueryProviderFactory());
50+
$this->schemaFactory->addTypeMapperFactory(new \GraphQL\RexTypeMapperFactory());
4751
if (static::isDebug()) {
4852
$this->schemaFactory->devMode();
4953
} else {
@@ -55,7 +59,7 @@ private function generateSchema(): Schema
5559
private function readInput(): array
5660
{
5761
$rawInput = file_get_contents('php://input');
58-
$value = \rex_var::toArray($rawInput);
62+
$value = rex_var::toArray($rawInput);
5963
if (is_array($value)) {
6064
return $value;
6165
}
@@ -64,28 +68,28 @@ private function readInput(): array
6468

6569
public static function registerEndpoint(): void
6670
{
67-
$endpoint = new Endpoint();
71+
$endpoint = new self();
6872
$result = $endpoint->executeQuery();
6973
static::sendResponse($result);
7074
}
7175

7276
private static function sendResponse(array $output): void
7377
{
74-
\rex_response::cleanOutputBuffers();
75-
\rex_response::sendCacheControl();
76-
\rex_response::setStatus(\rex_response::HTTP_OK);
77-
\rex_response::setHeader('Access-Control-Allow-Origin', '*');
78-
\rex_response::setHeader('Access-Control-Allow-Headers', 'Content-Type');
78+
rex_response::cleanOutputBuffers();
79+
rex_response::sendCacheControl();
80+
rex_response::setStatus(rex_response::HTTP_OK);
81+
rex_response::setHeader('Access-Control-Allow-Origin', '*');
82+
rex_response::setHeader('Access-Control-Allow-Headers', 'Content-Type');
7983
$output = json_encode($output);
80-
$output = \rex_extension::registerPoint(new \rex_extension_point('GRAPHQL_OUTPUT_FILTER', $output));
81-
\rex_response::sendContent($output, 'application/json');
84+
$output = rex_extension::registerPoint(new rex_extension_point('GRAPHQL_OUTPUT_FILTER', $output));
85+
rex_response::sendContent($output, 'application/json');
8286
exit;
8387
}
8488

8589
private static function isDebug(): bool
8690
{
87-
return \rex_extension::registerPoint(
88-
new \rex_extension_point('GRAPHQL_DEBUG', \rex::isDebugMode())
91+
return rex_extension::registerPoint(
92+
new rex_extension_point('GRAPHQL_DEBUG', rex::isDebugMode()),
8993
);
9094
}
9195
}

lib/Service/Media/MediaService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GraphQL\Service\Media;
44

5-
use GraphQL\Type\Media\Media;
5+
use RexGraphQL\Type\Media\Media;
66

77
class MediaService
88
{

lib/Service/Navigation/NavigationService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GraphQL\Service\Navigation;
44

5-
use GraphQL\Type\Navigation\NavigationItem;
5+
use RexGraphQL\Type\Navigation\NavigationItem;
66
use TheCodingMachine\GraphQLite\Exceptions\GraphQLException;
77

88
class NavigationService

lib/Service/Sprog/WildCardService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GraphQL\Service\Sprog;
44

5-
use GraphQL\Type\Sprog\WildCard;
5+
use RexGraphQL\Type\Sprog\WildCard;
66

77
class WildCardService
88
{

lib/Service/Structure/ArticleService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GraphQL\Service\Structure;
44

5-
use GraphQL\Type\Structure\Article;
5+
use RexGraphQL\Type\Structure\Article;
66

77
class ArticleService
88
{

lib/Service/Structure/ArticleSliceService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GraphQL\Service\Structure;
44

5-
use GraphQL\Type\Structure\ArticleSlice;
5+
use RexGraphQL\Type\Structure\ArticleSlice;
66

77
class ArticleSliceService
88
{

lib/Service/Structure/CategoryService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GraphQL\Service\Structure;
44

5-
use GraphQL\Type\Structure\Category;
5+
use RexGraphQL\Type\Structure\Category;
66

77
class CategoryService
88
{

lib/Service/Structure/ClangService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GraphQL\Service\Structure;
44

5-
use GraphQL\Type\Structure\Clang;
5+
use RexGraphQL\Type\Structure\Clang;
66
use TheCodingMachine\GraphQLite\Exceptions\GraphQLException;
77

88
class ClangService

lib/Service/Structure/ContentTypeService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GraphQL\Service\Structure;
44

5-
use GraphQL\Type\Structure\ContentType;
5+
use RexGraphQL\Type\Structure\ContentType;
66
use rex;
77
use rex_addon;
88
use rex_clang;

lib/Type/Media/Media.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace GraphQL\Type\Media;
3+
namespace RexGraphQL\Type\Media;
44

55
use TheCodingMachine\GraphQLite\Types\ID;
66
use TheCodingMachine\GraphQLite\Annotations\Field;

lib/Type/Navigation/NavigationItem.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace GraphQL\Type\Navigation;
3+
namespace RexGraphQL\Type\Navigation;
44

55
use TheCodingMachine\GraphQLite\Annotations\Field;
66
use TheCodingMachine\GraphQLite\Annotations\Type;
@@ -11,13 +11,13 @@ class NavigationItem
1111
{
1212

1313
private $id;
14-
private string $label;
15-
private string $url;
14+
private ?string $label;
15+
private ?string $url;
1616
private ?int $parentId;
17-
private bool $isActive;
18-
private bool $internal;
17+
private ?bool $isActive;
18+
private ?bool $internal;
1919

20-
public function __construct($id, string $label, string $url, ?int $parentId, bool $isActive, bool $internal)
20+
public function __construct(mixed $id = null, ?string $label = null, ?string $url = null, ?int $parentId = null, ?bool $isActive = null, ?bool $internal = null)
2121
{
2222
$this->id = $id;
2323
$this->label = $label;

lib/Type/Sprog/WildCard.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<?php
22

3-
namespace GraphQL\Type\Sprog;
3+
namespace RexGraphQL\Type\Sprog;
44

5-
use GraphQL\Type\Structure\Clang;
5+
use RexGraphQL\Type\Structure\Clang;
66
use TheCodingMachine\GraphQLite\Annotations\Field;
77
use TheCodingMachine\GraphQLite\Annotations\Type;
88
use TheCodingMachine\GraphQLite\Types\ID;
99

1010
#[Type]
1111
class WildCard
1212
{
13-
private int $id;
14-
private string $wildcard;
15-
private string $replace;
16-
private int $clangId;
13+
private ?int $id;
14+
private ?string $wildcard;
15+
private ?string $replace;
16+
private ?int $clangId;
1717

18-
public function __construct(int $id, string $wildcard, string $replace, int $clangId)
18+
public function __construct(int $id = null, string $wildcard= null, string $replace= null, int $clangId= null)
1919
{
2020
$this->id = $id;
2121
$this->wildcard = $wildcard;

lib/Type/Structure/Article.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace GraphQL\Type\Structure;
3+
namespace RexGraphQL\Type\Structure;
44

55
use DateTimeInterface;
66
use rex_article;

0 commit comments

Comments
 (0)