1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\GraphQL\Field; |
6
|
|
|
|
7
|
|
|
use Andi\GraphQL\Argument\Argument; |
8
|
|
|
use Andi\GraphQL\Definition\Field\ArgumentsAwareInterface; |
9
|
|
|
use Andi\GraphQL\Definition\Field\ComplexityAwareInterface; |
10
|
|
|
use Andi\GraphQL\Definition\Field\ObjectFieldInterface; |
11
|
|
|
use Andi\GraphQL\Definition\Field\ResolveAwareInterface; |
12
|
|
|
use Andi\GraphQL\Definition\Field\TypeAwareInterface; |
13
|
|
|
use App\GraphQL\Type\User; |
14
|
|
|
use GraphQL\Type\Definition as Webonyx; |
15
|
|
|
|
16
|
|
|
final class UserFullName implements |
17
|
|
|
ObjectFieldInterface, |
18
|
|
|
ArgumentsAwareInterface, |
19
|
|
|
ResolveAwareInterface, |
20
|
|
|
ComplexityAwareInterface |
21
|
|
|
{ |
22
|
|
|
public function getName(): string |
23
|
|
|
{ |
24
|
|
|
return 'fullName'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getDescription(): ?string |
28
|
|
|
{ |
29
|
|
|
return null; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getDeprecationReason(): ?string |
33
|
|
|
{ |
34
|
|
|
return null; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getType(): string |
38
|
|
|
{ |
39
|
|
|
return 'String'; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getMode(): int |
43
|
|
|
{ |
44
|
|
|
return TypeAwareInterface::IS_REQUIRED; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getArguments(): iterable |
48
|
|
|
{ |
49
|
|
|
yield new Argument( |
50
|
|
|
name: 'separator', |
51
|
|
|
type: 'String', |
52
|
|
|
mode: TypeAwareInterface::IS_REQUIRED, |
53
|
|
|
defaultValue: ' ', |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function resolve(mixed $objectValue, array $args, mixed $context, Webonyx\ResolveInfo $info): mixed |
58
|
|
|
{ |
59
|
|
|
/** @var User $objectValue */ |
60
|
|
|
return implode( |
61
|
|
|
$args['separator'], |
62
|
|
|
[ |
63
|
|
|
$objectValue->getLastname(), |
64
|
|
|
$objectValue->getFirstname(), |
65
|
|
|
(new \ReflectionProperty($objectValue, 'middlename'))->getValue($objectValue), |
66
|
|
|
], |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function complexity(int $childrenComplexity, array $args): int |
71
|
|
|
{ |
72
|
|
|
return $childrenComplexity + 1; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|