andrey-mokhov /
graphql-php
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Andi\GraphQL\Field; |
||
| 6 | |||
| 7 | use Andi\GraphQL\Common\ResolverArguments; |
||
| 8 | use GraphQL\Type\Definition as Webonyx; |
||
| 9 | use Spiral\Core\InvokerInterface; |
||
| 10 | use Spiral\Core\ScopeInterface; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @see Webonyx\FieldDefinition |
||
| 14 | * |
||
| 15 | * @phpstan-import-type FieldDefinitionConfig from Webonyx\FieldDefinition |
||
| 16 | */ |
||
| 17 | final class OuterObjectField extends Webonyx\FieldDefinition |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @param FieldDefinitionConfig $config |
||
| 21 | * @param class-string $class |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 22 | * @param string $method |
||
| 23 | * @param array<string,string> $argumentsMap |
||
| 24 | * @param ScopeInterface $scope |
||
| 25 | * @param InvokerInterface $invoker |
||
| 26 | */ |
||
| 27 | 3 | public function __construct( |
|
| 28 | array $config, |
||
| 29 | private readonly string $class, |
||
| 30 | private readonly string $method, |
||
| 31 | private readonly array $argumentsMap, |
||
| 32 | private readonly ScopeInterface $scope, |
||
| 33 | private readonly InvokerInterface $invoker, |
||
| 34 | ) { |
||
| 35 | 3 | $config['resolve'] = $this->resolve(...); |
|
| 36 | |||
| 37 | 3 | parent::__construct($config); |
|
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param mixed $object |
||
| 42 | * @param array<string,mixed> $args |
||
| 43 | * @param mixed $context |
||
| 44 | * @param Webonyx\ResolveInfo $info |
||
| 45 | * |
||
| 46 | * @return mixed |
||
| 47 | */ |
||
| 48 | 3 | private function resolve( |
|
| 49 | mixed $object, |
||
| 50 | array $args, |
||
| 51 | mixed $context, |
||
| 52 | Webonyx\ResolveInfo $info, |
||
| 53 | ): mixed { |
||
| 54 | 3 | $parameters = []; |
|
| 55 | 3 | foreach ($args as $name => $value) { |
|
| 56 | 3 | $parameters[$this->argumentsMap[$name] ?? $name] = $value; |
|
| 57 | } |
||
| 58 | |||
| 59 | 3 | return $this->scope->runScope( |
|
| 60 | 3 | [ResolverArguments::class => new ResolverArguments($object, $args, $context, $info)], |
|
| 61 | 3 | fn () => $this->invoker->invoke([$this->class, $this->method], $parameters), |
|
| 62 | 3 | ); |
|
| 63 | } |
||
| 64 | } |
||
| 65 |