1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Andi\GraphQL\InputObjectFieldResolver\Middleware; |
6
|
|
|
|
7
|
|
|
use Andi\GraphQL\Common\LazyType; |
8
|
|
|
use Andi\GraphQL\Definition\Field\DefaultValueAwareInterface; |
9
|
|
|
use Andi\GraphQL\Definition\Field\DeprecationReasonAwareInterface; |
10
|
|
|
use Andi\GraphQL\Definition\Field\InputObjectFieldInterface; |
11
|
|
|
use Andi\GraphQL\InputObjectFieldResolver\InputObjectFieldResolverInterface; |
12
|
|
|
use Andi\GraphQL\TypeRegistryInterface; |
13
|
|
|
use GraphQL\Type\Definition as Webonyx; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @see Webonyx\InputObjectField |
17
|
|
|
* |
18
|
|
|
* @phpstan-import-type InputObjectFieldConfig from Webonyx\InputObjectField |
19
|
|
|
*/ |
20
|
|
|
final class InputObjectFieldMiddleware implements MiddlewareInterface |
21
|
|
|
{ |
22
|
|
|
public const PRIORITY = 2048; |
23
|
|
|
|
24
|
4 |
|
public function __construct( |
25
|
|
|
private readonly TypeRegistryInterface $typeRegistry, |
26
|
|
|
) { |
27
|
4 |
|
} |
28
|
|
|
|
29
|
3 |
|
public function process(mixed $field, InputObjectFieldResolverInterface $fieldResolver): Webonyx\InputObjectField |
30
|
|
|
{ |
31
|
3 |
|
if (! $field instanceof InputObjectFieldInterface) { |
32
|
1 |
|
return $fieldResolver->resolve($field); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** @var InputObjectFieldConfig $config */ |
36
|
2 |
|
$config = [ |
37
|
2 |
|
'name' => $field->getName(), |
38
|
2 |
|
'description' => $field->getDescription(), |
39
|
2 |
|
'type' => new LazyType($field, $this->typeRegistry), |
40
|
2 |
|
]; |
41
|
|
|
|
42
|
2 |
|
if ($field instanceof DeprecationReasonAwareInterface) { |
43
|
2 |
|
$config['deprecationReason'] = $field->getDeprecationReason(); |
44
|
|
|
} |
45
|
|
|
|
46
|
2 |
|
if ($field instanceof DefaultValueAwareInterface && $field->hasDefaultValue()) { |
47
|
1 |
|
$config['defaultValue'] = $field->getDefaultValue(); |
48
|
|
|
} |
49
|
|
|
|
50
|
2 |
|
return new Webonyx\InputObjectField($config); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|