1
|
|
|
<?php |
2
|
|
|
/******************************************************************************* |
3
|
|
|
* This file is part of the GraphQL Bundle package. |
4
|
|
|
* |
5
|
|
|
* (c) YnloUltratech <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
******************************************************************************/ |
10
|
|
|
|
11
|
|
|
namespace Ynlo\GraphQLBundle\Type\Definition; |
12
|
|
|
|
13
|
|
|
use GraphQL\Type\Definition\ObjectType; |
14
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
17
|
|
|
use Ynlo\GraphQLBundle\Definition\ObjectDefinition; |
18
|
|
|
use Ynlo\GraphQLBundle\Resolver\DeferredBuffer; |
19
|
|
|
use Ynlo\GraphQLBundle\Resolver\ObjectFieldResolver; |
20
|
|
|
use Ynlo\GraphQLBundle\Type\Registry\TypeRegistry; |
21
|
|
|
use Ynlo\GraphQLBundle\Util\GraphQLBuilder; |
22
|
|
|
|
23
|
|
|
class ObjectDefinitionType extends ObjectType implements |
24
|
|
|
ContainerAwareInterface, |
25
|
|
|
EndpointAwareInterface |
26
|
|
|
{ |
27
|
|
|
use ContainerAwareTrait; |
28
|
|
|
use EndpointAwareTrait; |
29
|
|
|
|
30
|
|
|
protected $definition; |
31
|
|
|
|
32
|
|
|
public function __construct(ObjectDefinition $definition) |
33
|
22 |
|
{ |
34
|
|
|
$this->definition = $definition; |
35
|
22 |
|
|
36
|
|
|
parent::__construct( |
37
|
22 |
|
[ |
38
|
|
|
'name' => $definition->getName(), |
39
|
22 |
|
'description' => $definition->getDescription(), |
40
|
22 |
|
'fields' => function () use ($definition) { |
41
|
22 |
|
return GraphQLBuilder::resolveFields($definition); |
42
|
22 |
|
}, |
43
|
22 |
|
'interfaces' => function () { |
44
|
22 |
|
return $this->resolveInterfaces(); |
45
|
22 |
|
}, |
46
|
22 |
|
'resolveField' => function ($root, array $args, $context, ResolveInfo $resolveInfo) { |
47
|
22 |
|
$resolver = new ObjectFieldResolver( |
48
|
22 |
|
$this->container, |
49
|
22 |
|
$this->endpoint, |
50
|
22 |
|
$this->definition, |
51
|
22 |
|
$this->container->get(DeferredBuffer::class), |
52
|
22 |
|
$this->container->get('graphql.security.authorization_checker') |
53
|
22 |
|
); |
54
|
|
|
|
55
|
|
|
return $resolver($root, $args, $context, $resolveInfo); |
56
|
22 |
|
} |
57
|
22 |
|
] |
58
|
22 |
|
); |
59
|
|
|
} |
60
|
22 |
|
|
61
|
|
|
private function resolveInterfaces(): array |
62
|
|
|
{ |
63
|
22 |
|
$interfaces = []; |
64
|
|
|
foreach ($this->definition->getInterfaces() as $interface) { |
65
|
22 |
|
$interfaces[] = TypeRegistry::get($interface); |
66
|
|
|
} |
67
|
22 |
|
|
68
|
22 |
|
return $interfaces; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|