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