|
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\InputObjectType; |
|
14
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
|
17
|
|
|
use Ynlo\GraphQLBundle\Definition\InputObjectDefinition; |
|
18
|
|
|
use Ynlo\GraphQLBundle\Resolver\FieldExecutionContext; |
|
19
|
|
|
use Ynlo\GraphQLBundle\Resolver\ObjectFieldResolver; |
|
20
|
|
|
use Ynlo\GraphQLBundle\Resolver\QueryExecutionContext; |
|
21
|
|
|
use Ynlo\GraphQLBundle\Util\GraphQLBuilder; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class InputObjectDefinitionType |
|
25
|
|
|
*/ |
|
26
|
|
|
class InputObjectDefinitionType extends InputObjectType implements |
|
27
|
|
|
ContainerAwareInterface, |
|
28
|
|
|
EndpointAwareInterface |
|
29
|
|
|
{ |
|
30
|
|
|
use ContainerAwareTrait; |
|
31
|
|
|
use EndpointAwareTrait; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var InputObjectDefinition |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $definition; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param InputObjectDefinition $definition |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(InputObjectDefinition $definition) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->definition = $definition; |
|
44
|
|
|
|
|
45
|
|
|
parent::__construct( |
|
46
|
|
|
[ |
|
47
|
|
|
'name' => $definition->getName(), |
|
48
|
|
|
'description' => $definition->getDescription(), |
|
49
|
|
|
'fields' => function () use ($definition) { |
|
50
|
|
|
return GraphQLBuilder::resolveFields($definition); |
|
51
|
|
|
}, |
|
52
|
|
|
'resolveField' => function ($root, array $args, QueryExecutionContext $context, ResolveInfo $resolveInfo) use ($definition) { |
|
53
|
|
|
$resolver = new ObjectFieldResolver($this->container); |
|
54
|
|
|
|
|
55
|
|
|
return $resolver($root, $args, new FieldExecutionContext($context, $definition), $resolveInfo); |
|
56
|
|
|
}, |
|
57
|
|
|
] |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|