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:53 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Youshido\GraphQL\Config\Schema; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use Youshido\GraphQL\Config\AbstractConfig; |
13
|
|
|
use Youshido\GraphQL\Type\Object\AbstractObjectType; |
14
|
|
|
use Youshido\GraphQL\Type\Object\ObjectType; |
15
|
|
|
use Youshido\GraphQL\Type\SchemaDirectivesList; |
16
|
|
|
use Youshido\GraphQL\Type\SchemaTypesList; |
17
|
|
|
use Youshido\GraphQL\Type\TypeService; |
18
|
|
|
|
19
|
|
|
class SchemaConfig extends AbstractConfig |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var SchemaTypesList |
24
|
|
|
*/ |
25
|
|
|
private $typesList; |
26
|
|
|
/** |
27
|
|
|
* @var SchemaDirectivesList; |
28
|
|
|
*/ |
29
|
|
|
private $directiveList; |
30
|
|
|
|
31
|
82 |
|
public function __construct(array $configData, $contextObject = null, $finalClass = false) |
32
|
|
|
{ |
33
|
82 |
|
$this->typesList = new SchemaTypesList(); |
34
|
82 |
|
$this->directiveList = new SchemaDirectivesList(); |
35
|
82 |
|
parent::__construct($configData, $contextObject, $finalClass); |
36
|
82 |
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
View Code Duplication |
public function getRules() |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
return [ |
42
|
|
|
'query' => ['type' => TypeService::TYPE_OBJECT_TYPE, 'required' => true], |
43
|
|
|
'mutation' => ['type' => TypeService::TYPE_OBJECT_TYPE], |
44
|
|
|
'types' => ['type' => TypeService::TYPE_ARRAY], |
45
|
|
|
'directives' => ['type' => TypeService::TYPE_ARRAY], |
46
|
|
|
'name' => ['type' => TypeService::TYPE_STRING], |
47
|
|
|
]; |
48
|
|
|
} |
49
|
|
|
|
50
|
82 |
|
protected function build() |
51
|
|
|
{ |
52
|
82 |
|
parent::build(); |
53
|
82 |
|
if (!empty($this->data['types'])) { |
54
|
|
|
$this->typesList->addTypes($this->data['types']); |
55
|
|
|
} |
56
|
82 |
|
if (!empty($this->data['directives'])) { |
57
|
|
|
$this->directiveList->addDirectives($this->data['directives']); |
58
|
|
|
} |
59
|
82 |
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return AbstractObjectType |
64
|
|
|
*/ |
65
|
82 |
|
public function getQuery() |
66
|
|
|
{ |
67
|
82 |
|
return $this->data['query']; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param $query AbstractObjectType |
72
|
|
|
* |
73
|
|
|
* @return SchemaConfig |
74
|
|
|
*/ |
75
|
14 |
|
public function setQuery($query) |
76
|
|
|
{ |
77
|
14 |
|
$this->data['query'] = $query; |
78
|
|
|
|
79
|
14 |
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return ObjectType |
84
|
|
|
*/ |
85
|
25 |
|
public function getMutation() |
86
|
|
|
{ |
87
|
25 |
|
return $this->get('mutation'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param $query AbstractObjectType |
92
|
|
|
* |
93
|
|
|
* @return SchemaConfig |
94
|
|
|
*/ |
95
|
5 |
|
public function setMutation($query) |
96
|
|
|
{ |
97
|
5 |
|
$this->data['mutation'] = $query; |
98
|
|
|
|
99
|
5 |
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getName() |
103
|
|
|
{ |
104
|
|
|
return $this->get('name', 'RootSchema'); |
105
|
|
|
} |
106
|
|
|
|
107
|
9 |
|
public function getTypesList() |
108
|
|
|
{ |
109
|
9 |
|
return $this->typesList; |
110
|
|
|
} |
111
|
|
|
|
112
|
5 |
|
public function getDirectiveList() |
113
|
|
|
{ |
114
|
5 |
|
return $this->directiveList; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.