|
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\Type\Definition\ResolveInfo; |
|
13
|
|
|
use Railt\Container\ContainerInterface; |
|
|
|
|
|
|
14
|
|
|
use Railt\Http\RequestInterface; |
|
|
|
|
|
|
15
|
|
|
use Railt\Reflection\Contracts\Definitions\ObjectDefinition; |
|
|
|
|
|
|
16
|
|
|
use Railt\Reflection\Contracts\Definitions\TypeDefinition; |
|
|
|
|
|
|
17
|
|
|
use Railt\Reflection\Contracts\Dependent\FieldDefinition; |
|
|
|
|
|
|
18
|
|
|
use Railt\Reflection\Contracts\Invocations\DirectiveInvocation; |
|
|
|
|
|
|
19
|
|
|
use Railt\Routing\Contracts\InputInterface; |
|
|
|
|
|
|
20
|
|
|
use Railt\Routing\Contracts\RouterInterface; |
|
|
|
|
|
|
21
|
|
|
use Railt\Routing\GraphQL\RouteDirective; |
|
|
|
|
|
|
22
|
|
|
use Railt\Routing\Route; |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class FieldResolver |
|
26
|
|
|
*/ |
|
27
|
|
|
class FieldResolver |
|
28
|
|
|
{ |
|
29
|
|
|
private const DIRECTIVE = RouteDirective::DIRECTIVE_NAME; |
|
30
|
|
|
private const DIRECTIVE_ACTION = RouteDirective\ActionArgument::ARGUMENT_NAME; |
|
|
|
|
|
|
31
|
|
|
private const DIRECTIVE_OPERATION = RouteDirective\OperationArgument::ARGUMENT_NAME; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var ContainerInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private $container; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var RouterInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
private $router; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* FieldResolver constructor. |
|
45
|
|
|
* @param ContainerInterface $container |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct(ContainerInterface $container) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->container = $container; |
|
50
|
|
|
$this->router = $container->make(RouterInterface::class); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param RequestInterface $request |
|
55
|
|
|
* @param FieldDefinition $field |
|
56
|
|
|
* @return \Closure|null |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getCallback(RequestInterface $request, FieldDefinition $field): ?\Closure |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
/** @var ObjectDefinition $object */ |
|
61
|
|
|
$object = $field->getParent(); |
|
62
|
|
|
|
|
63
|
|
|
$this->loadRouteDirective($object, $field); |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
if (! $this->router->has($object)) { |
|
67
|
|
|
return null; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** @var Route $route */ |
|
71
|
|
|
$route = $this->router->get($object); |
|
72
|
|
|
|
|
73
|
|
|
// TODO Match operation |
|
74
|
|
|
// $request->getOperation() |
|
75
|
|
|
|
|
76
|
|
|
// TODO Match method |
|
77
|
|
|
// $request->getMethod() |
|
78
|
|
|
|
|
79
|
|
|
return function ($parent, array $arguments = [], $ctx, ResolveInfo $info) use ($route, $field) { |
|
80
|
|
|
return $route->call([ |
|
81
|
|
|
InputInterface::class => new Input($field, $info, $arguments, $parent), |
|
82
|
|
|
TypeDefinition::class => $field, |
|
83
|
|
|
'parent' => $parent, |
|
84
|
|
|
]); |
|
85
|
|
|
}; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param ObjectDefinition $object |
|
90
|
|
|
* @param FieldDefinition $field |
|
91
|
|
|
* @return void |
|
92
|
|
|
*/ |
|
93
|
|
|
private function loadRouteDirective(ObjectDefinition $object, FieldDefinition $field): void |
|
94
|
|
|
{ |
|
95
|
|
|
if (! $field->hasDirective(self::DIRECTIVE)) { |
|
96
|
|
|
return; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** @var DirectiveInvocation $directive */ |
|
100
|
|
|
$directive = $field->getDirective(self::DIRECTIVE); |
|
101
|
|
|
|
|
102
|
|
|
$urn = (string)$directive->getPassedArgument(self::DIRECTIVE_ACTION)->getPassedValue(); |
|
103
|
|
|
|
|
104
|
|
|
$route = $this->router->route($object, $field->getName()) |
|
|
|
|
|
|
105
|
|
|
->then($this->createCallback($urn)); |
|
106
|
|
|
|
|
107
|
|
|
// TODO Add operations |
|
108
|
|
|
// TODO Add method |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param string $urn |
|
113
|
|
|
* @return \Closure |
|
114
|
|
|
*/ |
|
115
|
|
|
private function createCallback(string $urn): \Closure |
|
116
|
|
|
{ |
|
117
|
|
|
[$controller, $action] = \explode('@', $urn); |
|
118
|
|
|
|
|
119
|
|
|
return \Closure::fromCallable([ |
|
120
|
|
|
$this->container->make($controller), |
|
121
|
|
|
$action, |
|
122
|
|
|
]); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
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