3
3
namespace GraphQL ;
4
4
5
5
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 ;
9
11
use Symfony \Component \DependencyInjection \Container ;
10
12
use TheCodingMachine \GraphQLite \Context \Context ;
11
13
use TheCodingMachine \GraphQLite \Exceptions \WebonyxErrorHandler ;
12
14
use TheCodingMachine \GraphQLite \Schema ;
13
15
use TheCodingMachine \GraphQLite \SchemaFactory ;
14
16
use Yiisoft \Cache \ArrayCache ;
15
17
18
+ use function is_array ;
19
+
16
20
class Endpoint
17
21
{
18
22
private SchemaFactory $ schemaFactory ;
19
23
20
24
public function __construct ()
21
25
{
22
26
$ this ->schemaFactory = new SchemaFactory (
23
- new ArrayCache (), new Container ()
27
+ new ArrayCache (), new Container (),
24
28
);
25
29
}
26
30
@@ -34,16 +38,16 @@ public function executeQuery(): array
34
38
$ input ['query ' ],
35
39
null ,
36
40
new Context (),
37
- $ input ['variables ' ] ?? null
41
+ $ input ['variables ' ] ?? null ,
38
42
)->setErrorFormatter ([WebonyxErrorHandler::class, 'errorFormatter ' ])
39
43
->setErrorsHandler ([WebonyxErrorHandler::class, 'errorHandler ' ])
40
44
->toArray (self ::isDebug () ? DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE : DebugFlag::NONE );
41
45
}
42
46
43
47
private function generateSchema (): Schema
44
48
{
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 ());
47
51
if (static ::isDebug ()) {
48
52
$ this ->schemaFactory ->devMode ();
49
53
} else {
@@ -55,7 +59,7 @@ private function generateSchema(): Schema
55
59
private function readInput (): array
56
60
{
57
61
$ rawInput = file_get_contents ('php://input ' );
58
- $ value = \ rex_var::toArray ($ rawInput );
62
+ $ value = rex_var::toArray ($ rawInput );
59
63
if (is_array ($ value )) {
60
64
return $ value ;
61
65
}
@@ -64,28 +68,28 @@ private function readInput(): array
64
68
65
69
public static function registerEndpoint (): void
66
70
{
67
- $ endpoint = new Endpoint ();
71
+ $ endpoint = new self ();
68
72
$ result = $ endpoint ->executeQuery ();
69
73
static ::sendResponse ($ result );
70
74
}
71
75
72
76
private static function sendResponse (array $ output ): void
73
77
{
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 ' );
79
83
$ 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 ' );
82
86
exit ;
83
87
}
84
88
85
89
private static function isDebug (): bool
86
90
{
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 ()),
89
93
);
90
94
}
91
95
}
0 commit comments