Passed
Push — master ( 43996d...1595cb )
by Kirill
04:07
created

InterfaceTypeDefinitionContext::resolve()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 21
rs 9.9332
c 0
b 0
f 0
cc 4
nc 8
nop 1
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\InterfaceTypeInterface;
15
use Railt\SDL\Backend\Context;
16
use Railt\SDL\Frontend\Ast\Definition\Type\InterfaceTypeDefinitionNode;
17
use Railt\TypeSystem\Exception\TypeUniquenessException;
18
use Railt\TypeSystem\Schema;
19
use Railt\TypeSystem\Type\InterfaceType;
20
21
/**
22
 * @property-read InterfaceTypeDefinitionNode $ast
23
 * @method InterfaceTypeDefinitionNode getAst()
24
 */
25
class InterfaceTypeDefinitionContext extends NamedTypeContext
26
{
27
    /**
28
     * InterfaceTypeDefinitionContext constructor.
29
     *
30
     * @param Context $context
31
     * @param Schema $schema
32
     * @param InterfaceTypeDefinitionNode $ast
33
     */
34
    public function __construct(Context $context, Schema $schema, InterfaceTypeDefinitionNode $ast)
35
    {
36
        parent::__construct($context,  $schema, $ast);
37
    }
38
39
    /**
40
     * @param array $variables
41
     * @return InterfaceTypeInterface
42
     * @throws TypeUniquenessException
43
     * @throws \InvalidArgumentException
44
     * @throws \Throwable
45
     */
46
    public function resolve(array $variables = []): InterfaceTypeInterface
47
    {
48
        $ast = $this->precompile($this->ast, $variables);
49
        
50
        $interface = new InterfaceType($ast->name->value, [
51
            'description' => $this->descriptionOf($ast),
52
        ]);
53
54
        foreach ($ast->interfaces as $impl) {
55
            $interface->addInterface($this->ref($impl->interface));
56
        }
57
58
        foreach ($ast->fields as $field) {
59
            $interface->addField($this->buildFieldDefinition($field));
60
        }
61
62
        foreach ($ast->directives as $directive) {
63
            $this->executeDirective($interface, $directive);
64
        }
65
66
        return $interface;
67
    }
68
}
69