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
|
|
|
use Youshido\GraphQL\Parser\Ast\Interfaces\FieldInterface; |
11
|
|
|
use Youshido\GraphQL\Parser\Ast\Interfaces\FragmentInterface; |
12
|
|
|
use Youshido\GraphQL\Parser\Location; |
13
|
|
|
|
14
|
|
|
class Query extends AbstractAst implements FieldInterface |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
use AstArgumentsTrait; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
protected $name; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
protected $alias; |
24
|
|
|
|
25
|
|
|
/** @var Field[]|Query[] */ |
26
|
|
|
protected $fields = []; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Query constructor. |
30
|
|
|
* |
31
|
|
|
* @param string $name |
32
|
|
|
* @param string $alias |
33
|
|
|
* @param array $arguments |
34
|
|
|
* @param array $fields |
35
|
|
|
* @param Location $location |
36
|
|
|
*/ |
37
|
85 |
|
public function __construct($name, $alias = '', array $arguments, array $fields, Location $location) |
38
|
|
|
{ |
39
|
85 |
|
parent::__construct($location); |
40
|
|
|
|
41
|
85 |
|
$this->name = $name; |
42
|
85 |
|
$this->alias = $alias; |
43
|
85 |
|
$this->setFields($fields); |
44
|
85 |
|
$this->setArguments($arguments); |
45
|
85 |
|
} |
46
|
|
|
|
47
|
60 |
|
public function getName() |
48
|
|
|
{ |
49
|
60 |
|
return $this->name; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return Field[]|Query[]|FragmentInterface[] |
54
|
|
|
*/ |
55
|
54 |
|
public function getFields() |
56
|
|
|
{ |
57
|
54 |
|
return array_values($this->fields); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return bool |
62
|
|
|
*/ |
63
|
22 |
|
public function hasFields() |
64
|
|
|
{ |
65
|
22 |
|
return (bool)count($this->fields); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param Field[]|Query[] $fields |
70
|
|
|
*/ |
71
|
85 |
|
public function setFields($fields) |
72
|
|
|
{ |
73
|
|
|
/** |
74
|
|
|
* we cannot store fields by name because of TypedFragments |
75
|
|
|
*/ |
76
|
85 |
|
$this->fields = $fields; |
|
|
|
|
77
|
85 |
|
} |
78
|
|
|
|
79
|
60 |
|
public function getAlias() |
80
|
|
|
{ |
81
|
60 |
|
return $this->alias; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function hasField($name, $deep = false) |
85
|
|
|
{ |
86
|
|
|
foreach ($this->getFields() as $field) { |
87
|
|
|
if ($field->getName() == $name) { |
88
|
|
|
return true; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if ($deep && $field instanceof Query) { |
92
|
|
|
if ($field->hasField($name)) { |
93
|
|
|
return true; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return false; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
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..