andrey-mokhov /
graphql-php-spiral
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Andi\GraphQL\Spiral\Common; |
||
| 6 | |||
| 7 | use GraphQL\Language\AST\DocumentNode; |
||
| 8 | use GraphQL\Server\OperationParams; |
||
| 9 | use Spiral\Core\InvokerInterface; |
||
| 10 | use Spiral\Core\ScopeInterface; |
||
| 11 | |||
| 12 | final class ValueResolver |
||
| 13 | { |
||
| 14 | private readonly \Closure $factoryFn; |
||
| 15 | |||
| 16 | 4 | public function __construct( |
|
| 17 | private readonly ScopeInterface $scope, |
||
| 18 | private readonly InvokerInterface $invoker, |
||
| 19 | callable $factory, |
||
| 20 | ) { |
||
| 21 | 4 | $this->factoryFn = $factory instanceof \Closure |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 22 | 2 | ? $factory |
|
| 23 | 2 | : $factory(...); |
|
| 24 | } |
||
| 25 | |||
| 26 | 3 | public function __invoke(OperationParams $params, DocumentNode $doc, string $operationType): mixed |
|
| 27 | { |
||
| 28 | 3 | return $this->scope->runScope( |
|
| 29 | 3 | [OperationParams::class => $params, DocumentNode::class => $doc], |
|
| 30 | 3 | fn () => $this->invoker->invoke($this->factoryFn, ['operationType' => $operationType]), |
|
| 31 | 3 | ); |
|
| 32 | } |
||
| 33 | } |
||
| 34 |