Completed
Push — master ( f8702a...461e07 )
by Alexandr
04:08
created

AbstractSchema::getQueryType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 5/5/16 9:24 PM
7
*/
8
9
namespace Youshido\GraphQL;
10
11
12
use Youshido\GraphQL\Type\Config\Schema\SchemaConfig;
13
use Youshido\GraphQL\Type\Object\AbstractObjectType;
14
use Youshido\GraphQL\Type\Object\ObjectType;
15
16
abstract class AbstractSchema
17
{
18
19
    /** @var SchemaConfig */
20
    protected $config;
21
22 22
    public function __construct($config = [])
23
    {
24 22
        if (!array_key_exists('query', $config)) {
25 16
            $config['query'] = new ObjectType(['name' => $this->getName() . 'Query']);
26
        }
27 22
        if (!array_key_exists('mutation', $config)) {
28 22
            $config['mutation'] = new ObjectType(['name' => $this->getName() . 'Mutation']);
29
        }
30
31 22
        $this->config = new SchemaConfig($config, $this);
32
33 21
        $this->build($this->config);
34 21
    }
35
36
    abstract public function build(SchemaConfig $config);
37
38 20
    public function addQuery($name, AbstractObjectType $query, $config = [])
39
    {
40 20
        $this->getQueryType()->getConfig()->addField($name, $query, $config);
41 20
    }
42
43
    public function addMutation($name, AbstractObjectType $query, $config = [])
44
    {
45
        $this->getMutationType()->getConfig()->addField($name, $query, $config);
46
    }
47
48 20
    final public function getQueryType()
49
    {
50 20
        return $this->config->getQuery();
51
    }
52
53 3
    final public function getMutationType()
54
    {
55 3
        return $this->config->getMutation();
56
    }
57
58 21
    public function getName()
59
    {
60 21
        $defaultName = 'RootSchema';
61
62 21
        return $this->config ? $this->config->get('name', $defaultName) : $defaultName;
63
    }
64
}
65