1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Andi\GraphQL\Field; |
6
|
|
|
|
7
|
|
|
use Andi\GraphQL\Argument\Argument; |
8
|
|
|
use Andi\GraphQL\Definition\Field\ArgumentInterface; |
9
|
|
|
use Andi\GraphQL\Definition\Field\ArgumentsAwareInterface; |
10
|
|
|
use Andi\GraphQL\Definition\Field\ObjectFieldInterface; |
11
|
|
|
use GraphQL\Type\Definition as Webonyx; |
12
|
|
|
|
13
|
|
|
abstract class AbstractObjectField implements ObjectFieldInterface, ArgumentsAwareInterface |
14
|
|
|
{ |
15
|
|
|
use FieldExtractorTrait; |
16
|
|
|
|
17
|
|
|
protected string $name; |
18
|
|
|
|
19
|
|
|
protected string $description; |
20
|
|
|
|
21
|
|
|
protected string $type; |
22
|
|
|
|
23
|
|
|
protected int $mode; |
24
|
|
|
|
25
|
|
|
protected string $deprecationReason; |
26
|
|
|
|
27
|
|
|
protected iterable $arguments; |
28
|
|
|
|
29
|
14 |
|
public function getName(): string |
30
|
|
|
{ |
31
|
14 |
|
return $this->name; |
32
|
|
|
} |
33
|
|
|
|
34
|
14 |
|
public function getDescription(): ?string |
35
|
|
|
{ |
36
|
|
|
/** @psalm-suppress RedundantPropertyInitializationCheck */ |
37
|
14 |
|
return $this->description ?? null; |
38
|
|
|
} |
39
|
|
|
|
40
|
14 |
|
public function getDeprecationReason(): ?string |
41
|
|
|
{ |
42
|
|
|
/** @psalm-suppress RedundantPropertyInitializationCheck */ |
43
|
14 |
|
return $this->deprecationReason ?? null; |
44
|
|
|
} |
45
|
|
|
|
46
|
14 |
|
public function getType(): string |
47
|
|
|
{ |
48
|
14 |
|
return $this->type; |
49
|
|
|
} |
50
|
|
|
|
51
|
14 |
|
public function getMode(): int |
52
|
|
|
{ |
53
|
|
|
/** @psalm-suppress RedundantPropertyInitializationCheck */ |
54
|
14 |
|
return $this->mode ?? 0; |
55
|
|
|
} |
56
|
|
|
|
57
|
14 |
|
public function getArguments(): iterable |
58
|
|
|
{ |
59
|
|
|
/** |
60
|
|
|
* @psalm-suppress RedundantPropertyInitializationCheck |
61
|
|
|
* @psalm-suppress RedundantCondition |
62
|
|
|
* @psalm-suppress TypeDoesNotContainType |
63
|
|
|
*/ |
64
|
14 |
|
foreach ($this->arguments ?? [] as $name => $argument) { |
65
|
1 |
|
if ($argument instanceof ArgumentInterface || $argument instanceof Webonyx\Type) { |
66
|
1 |
|
yield $argument; |
67
|
1 |
|
} elseif (\is_string($argument)) { |
68
|
1 |
|
yield new Argument($name, $argument); |
69
|
1 |
|
} elseif (\is_array($argument)) { |
70
|
1 |
|
if (\is_string($name)) { |
71
|
1 |
|
$argument['name'] ??= $name; |
72
|
|
|
} |
73
|
|
|
|
74
|
1 |
|
yield $this->extract($argument, Argument::class); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|