1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Railt package. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Railt\SDL\Backend\Context; |
13
|
|
|
|
14
|
|
|
use GraphQL\Contracts\TypeSystem\Type\ObjectTypeInterface; |
15
|
|
|
use Railt\SDL\Backend\Context; |
16
|
|
|
use Railt\SDL\Frontend\Ast\Definition\Type\ObjectTypeDefinitionNode; |
17
|
|
|
use Railt\TypeSystem\Exception\TypeUniquenessException; |
18
|
|
|
use Railt\TypeSystem\Schema; |
19
|
|
|
use Railt\TypeSystem\Type\ObjectType; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @property-read ObjectTypeDefinitionNode $ast |
23
|
|
|
* @method ObjectTypeDefinitionNode getAst() |
24
|
|
|
*/ |
25
|
|
|
class ObjectTypeDefinitionContext extends NamedTypeContext |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* ObjectTypeDefinitionContext constructor. |
29
|
|
|
* |
30
|
|
|
* @param Context $context |
31
|
|
|
* @param Schema $schema |
32
|
|
|
* @param ObjectTypeDefinitionNode $ast |
33
|
|
|
*/ |
34
|
|
|
public function __construct(Context $context, Schema $schema, ObjectTypeDefinitionNode $ast) |
35
|
|
|
{ |
36
|
|
|
parent::__construct($context, $schema, $ast); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param array $variables |
41
|
|
|
* @return ObjectTypeInterface |
42
|
|
|
* @throws TypeUniquenessException |
43
|
|
|
* @throws \InvalidArgumentException |
44
|
|
|
* @throws \Throwable |
45
|
|
|
*/ |
46
|
|
|
public function resolve(array $variables = []): ObjectTypeInterface |
47
|
|
|
{ |
48
|
|
|
$ast = $this->precompile($this->ast, $variables); |
49
|
|
|
|
50
|
|
|
$object = new ObjectType($ast->name->value, [ |
51
|
|
|
'description' => $this->descriptionOf($ast), |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
foreach ($ast->interfaces as $impl) { |
55
|
|
|
$object->addInterface($this->ref($impl->interface)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
foreach ($ast->fields as $field) { |
59
|
|
|
$object->addField($this->buildFieldDefinition($field)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
foreach ($ast->directives as $directive) { |
63
|
|
|
$this->executeDirective($object, $directive); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $object; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|