-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathstart.rr.php
62 lines (52 loc) · 3.27 KB
/
start.rr.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* This is will boot an async server, powered by https://reactphp.org/.
*/
require_once dirname(__FILE__).'/start.php';
use GraphQL\GraphQL;
use GraphQL\Type\Schema;
use Minds\Core\Data\cache\InMemoryCache;
use Minds\Core\Di\Di;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\Response;
use Spiral\RoadRunner\Http\PSR7Worker;
use Spiral\RoadRunner\Worker;
use TheCodingMachine\GraphQLite\Context\Context;
error_reporting(E_ERROR);
$worker = Worker::create();
$factory = new Psr17Factory();
$psr7 = new PSR7Worker($worker, $factory, $factory, $factory);
// Prewarm Graphql
try {
/** @var Schema */
$schema = Di::_()->get(Schema::class);
$result = GraphQL::executeQuery($schema, "\n query IntrospectionQuery {\n __schema {\n \n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n ...FullType\n }\n directives {\n name\n description\n \n locations\n args {\n ...InputValue\n }\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n description\n \n fields(includeDeprecated: true) {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n description\n type { ...TypeRef }\n defaultValue\n \n \n }\n\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n", null, new Context(), []);
} catch (\Exception $e) {
var_dump($e);
}
while (true) {
try {
$request = $psr7->waitRequest();
if ($request === null) {
break;
}
} catch (\Throwable $e) {
$psr7->respond(new Response(400));
continue;
}
try {
$router = new Minds\Core\Router();
$response = $router->handleRequest($request);
$psr7->respond($response);
} catch (\Throwable $e) {
$psr7->respond(new Response(500, [], 'Something Went Wrong!'));
$psr7->getWorker()->error((string) $e);
} finally {
// Clear the per-request caches
$cache = Di::_()->get(InMemoryCache::class);
$cache->clear();
// Tmp (needs refactoring at a lower level)
global $USERNAME_TO_GUID_MAP_CACHE;
$USERNAME_TO_GUID_MAP_CACHE = [];
}
}