Passed
Push — master ( 102634...08910a )
by Christoffer
02:20
created

SchemaBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 15 1
A __construct() 0 3 1
1
<?php
2
3
namespace Digia\GraphQL\Schema\Building;
4
5
use Digia\GraphQL\Error\LanguageException;
6
use Digia\GraphQL\Language\Node\DirectiveDefinitionNode;
7
use Digia\GraphQL\Language\Node\DocumentNode;
8
use Digia\GraphQL\Language\Node\NamedTypeNode;
9
use Digia\GraphQL\Language\Node\SchemaDefinitionNode;
10
use Digia\GraphQL\Language\Node\TypeDefinitionNodeInterface;
11
use Digia\GraphQL\Language\Node\TypeNodeInterface;
12
use Digia\GraphQL\Schema\ResolverRegistryInterface;
13
use Digia\GraphQL\Type\Definition\DirectiveInterface;
14
use Digia\GraphQL\Schema\SchemaInterface;
15
use function Digia\GraphQL\Type\GraphQLSchema;
16
use function Digia\GraphQL\Util\arraySome;
17
18
class SchemaBuilder implements SchemaBuilderInterface
19
{
20
    /**
21
     * @var BuilderContextCreatorInterface
22
     */
23
    protected $contextCreator;
24
25
    /**
26
     * SchemaBuilder constructor.
27
     * @param BuilderContextCreatorInterface $contextCreator
28
     */
29
    public function __construct(BuilderContextCreatorInterface $contextCreator)
30
    {
31
        $this->contextCreator = $contextCreator;
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function build(
38
        DocumentNode $document,
39
        ResolverRegistryInterface $resolverRegistry,
40
        array $options = []
41
    ): SchemaInterface {
42
        $context = $this->contextCreator->create($document, $resolverRegistry);
43
44
        return GraphQLSchema([
45
            'query'        => $context->buildQueryType(),
46
            'mutation'     => $context->buildMutationType(),
47
            'subscription' => $context->buildSubscriptionType(),
48
            'types'        => $context->buildTypes(),
49
            'directives'   => $context->buildDirectives(),
50
            'astNode'      => $context->getSchemaDefinition(),
51
            'assumeValid'  => $options['assumeValid'] ?? false,
52
        ]);
53
    }
54
}
55