|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Date: 23.11.15 |
|
4
|
|
|
* |
|
5
|
|
|
* @author Portey Vasil <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Youshido\GraphQL\Parser\Ast; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class Query |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** @var string */ |
|
15
|
|
|
protected $name; |
|
16
|
|
|
|
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
protected $alias; |
|
19
|
|
|
|
|
20
|
|
|
/** @var Argument[] */ |
|
21
|
|
|
protected $arguments; |
|
22
|
|
|
|
|
23
|
|
|
/** @var Field[]|Query[] */ |
|
24
|
|
|
protected $fields; |
|
25
|
|
|
|
|
26
|
52 |
|
public function __construct($name, $alias = null, $arguments = [], $fields = []) |
|
27
|
|
|
{ |
|
28
|
52 |
|
$this->name = $name; |
|
29
|
52 |
|
$this->alias = $alias; |
|
30
|
52 |
|
$this->arguments = $arguments; |
|
31
|
52 |
|
$this->fields = $fields; |
|
32
|
52 |
|
} |
|
33
|
|
|
|
|
34
|
29 |
|
public function getName() |
|
35
|
|
|
{ |
|
36
|
29 |
|
return $this->name; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
1 |
|
public function hasArguments() |
|
40
|
|
|
{ |
|
41
|
1 |
|
return (bool)count($this->arguments); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return Argument[] |
|
46
|
|
|
*/ |
|
47
|
30 |
|
public function getArguments() |
|
48
|
|
|
{ |
|
49
|
30 |
|
return $this->arguments; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param $arguments Argument[] |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function setArguments($arguments) |
|
56
|
|
|
{ |
|
57
|
1 |
|
$this->arguments = $arguments; |
|
58
|
1 |
|
} |
|
59
|
|
|
|
|
60
|
5 |
|
public function addArgument(Argument $argument) |
|
61
|
|
|
{ |
|
62
|
5 |
|
$this->arguments[$argument->getName()] = $argument; |
|
63
|
5 |
|
} |
|
64
|
|
|
|
|
65
|
3 |
|
public function getKeyValueArguments() |
|
66
|
|
|
{ |
|
67
|
3 |
|
$arguments = []; |
|
68
|
|
|
|
|
69
|
3 |
|
foreach ($this->getArguments() as $argument) { |
|
70
|
3 |
|
$arguments[$argument->getName()] = $argument->getValue()->getValue(); |
|
71
|
3 |
|
} |
|
72
|
|
|
|
|
73
|
3 |
|
return $arguments; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return Field[]|Query[]|FragmentInterface[] |
|
78
|
|
|
*/ |
|
79
|
26 |
|
public function getFields() |
|
80
|
|
|
{ |
|
81
|
26 |
|
return $this->fields; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return bool |
|
86
|
|
|
*/ |
|
87
|
24 |
|
public function hasFields() |
|
88
|
|
|
{ |
|
89
|
24 |
|
return (bool)count($this->fields); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param Field[]|Query[] $fields |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function setFields($fields) |
|
96
|
|
|
{ |
|
97
|
1 |
|
$this->fields = $fields; |
|
|
|
|
|
|
98
|
1 |
|
} |
|
99
|
|
|
|
|
100
|
29 |
|
public function getAlias() |
|
101
|
|
|
{ |
|
102
|
29 |
|
return $this->alias; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function hasField($name, $deep = false) |
|
106
|
|
|
{ |
|
107
|
|
|
foreach ($this->getFields() as $field) { |
|
108
|
|
|
if ($field->getName() == $name) { |
|
109
|
|
|
return true; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
if ($deep && $field instanceof Query) { |
|
113
|
|
|
if ($field->hasField($name)) { |
|
114
|
|
|
return true; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return false; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..