Passed
Push — master ( 98caf9...102634 )
by Christoffer
02:17
created

getOperationTypes()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 4
nop 2
dl 0
loc 22
rs 8.9197
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\SchemaBuilder;
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\Type\Definition\DirectiveInterface;
13
use Digia\GraphQL\Type\SchemaInterface;
14
use function Digia\GraphQL\Type\GraphQLSchema;
15
use function Digia\GraphQL\Util\arraySome;
16
17
class SchemaBuilder implements SchemaBuilderInterface
18
{
19
    /**
20
     * @var BuilderContextCreatorInterface
21
     */
22
    protected $contextCreator;
23
24
    /**
25
     * SchemaBuilder constructor.
26
     * @param BuilderContextCreatorInterface $contextCreator
27
     */
28
    public function __construct(BuilderContextCreatorInterface $contextCreator)
29
    {
30
        $this->contextCreator = $contextCreator;
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function build(
37
        DocumentNode $document,
38
        ResolverRegistryInterface $resolverRegistry,
39
        array $options = []
40
    ): SchemaInterface {
41
        $context = $this->contextCreator->create($document, $resolverRegistry);
42
43
        return GraphQLSchema([
44
            'query'        => $context->buildQueryType(),
45
            'mutation'     => $context->buildMutationType(),
46
            'subscription' => $context->buildSubscriptionType(),
47
            'types'        => $context->buildTypes(),
48
            'directives'   => $context->buildDirectives(),
49
            'astNode'      => $context->getSchemaDefinition(),
50
            'assumeValid'  => $options['assumeValid'] ?? false,
51
        ]);
52
    }
53
}
54