|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Railt package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Railt\Adapters\Webonyx; |
|
11
|
|
|
|
|
12
|
|
|
use GraphQL\Executor\ExecutionResult; |
|
13
|
|
|
use GraphQL\GraphQL; |
|
14
|
|
|
use GraphQL\Type\Schema; |
|
|
|
|
|
|
15
|
|
|
use Railt\Adapters\AdapterInterface; |
|
|
|
|
|
|
16
|
|
|
use Railt\Adapters\Webonyx\Builders\SchemaBuilder; |
|
17
|
|
|
use Railt\Container\ContainerInterface; |
|
|
|
|
|
|
18
|
|
|
use Railt\Http\RequestInterface; |
|
|
|
|
|
|
19
|
|
|
use Railt\Http\Response; |
|
|
|
|
|
|
20
|
|
|
use Railt\Http\ResponseInterface; |
|
|
|
|
|
|
21
|
|
|
use Railt\Reflection\Contracts\Definitions\SchemaDefinition; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class Adapter |
|
25
|
|
|
*/ |
|
26
|
|
|
class Adapter implements AdapterInterface |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var Registry |
|
30
|
|
|
*/ |
|
31
|
|
|
private $registry; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var bool |
|
35
|
|
|
*/ |
|
36
|
|
|
private $debug; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Adapter constructor. |
|
40
|
|
|
* @param ContainerInterface $container |
|
41
|
|
|
* @param bool $debug |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(ContainerInterface $container, bool $debug = false) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->debug = $debug; |
|
46
|
|
|
$this->registry = new Registry($container); |
|
47
|
|
|
$container->instance(FieldResolver::class, new FieldResolver($container)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param SchemaDefinition $schema |
|
52
|
|
|
* @param RequestInterface $request |
|
53
|
|
|
* @return ResponseInterface |
|
54
|
|
|
* @throws \GraphQL\Error\InvariantViolation |
|
55
|
|
|
* @throws \Throwable |
|
56
|
|
|
*/ |
|
57
|
|
|
public function request(SchemaDefinition $schema, RequestInterface $request): ResponseInterface |
|
58
|
|
|
{ |
|
59
|
|
|
$this->registry->getContainer()->instance(RequestInterface::class, $request); |
|
60
|
|
|
|
|
61
|
|
|
try { |
|
62
|
|
|
$executor = $this->buildExecutor($schema, $request); |
|
63
|
|
|
|
|
64
|
|
|
/** @var ExecutionResult $result */ |
|
65
|
|
|
$result = $executor(); |
|
66
|
|
|
|
|
67
|
|
|
return new Response((array)$result->data, $result->errors); |
|
68
|
|
|
} catch (\Throwable $e) { |
|
69
|
|
|
if ($this->debug) { |
|
70
|
|
|
throw $e; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return Response::error($e); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param SchemaDefinition $reflection |
|
79
|
|
|
* @param RequestInterface $request |
|
80
|
|
|
* @return \Closure |
|
81
|
|
|
* @throws \GraphQL\Error\InvariantViolation |
|
82
|
|
|
*/ |
|
83
|
|
|
private function buildExecutor(SchemaDefinition $reflection, RequestInterface $request): \Closure |
|
84
|
|
|
{ |
|
85
|
|
|
$schema = $this->buildSchema($reflection); |
|
86
|
|
|
|
|
87
|
|
|
if ($this->debug) { |
|
88
|
|
|
$schema->assertValid(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return function ($rootValue = null, $context = null) use ($reflection, $schema, $request): ExecutionResult { |
|
|
|
|
|
|
92
|
|
|
return GraphQL::executeQuery( |
|
|
|
|
|
|
93
|
|
|
$schema, |
|
94
|
|
|
$request->getQuery(), |
|
95
|
|
|
$rootValue, |
|
96
|
|
|
$reflection, |
|
97
|
|
|
$request->getVariables(), |
|
98
|
|
|
$request->getOperation(), |
|
99
|
|
|
null /** Validations */ |
|
100
|
|
|
); |
|
101
|
|
|
}; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param SchemaDefinition $schema |
|
106
|
|
|
* @return Schema |
|
107
|
|
|
*/ |
|
108
|
|
|
protected function buildSchema(SchemaDefinition $schema): Schema |
|
109
|
|
|
{ |
|
110
|
|
|
$builder = new SchemaBuilder($schema, $this->registry); |
|
111
|
|
|
|
|
112
|
|
|
return $builder->build(); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths