1 | <?php |
||
24 | class QueryType extends AbstractObjectType |
||
25 | { |
||
26 | |||
27 | use TypeCollectorTrait; |
||
28 | |||
29 | /** |
||
30 | * @return String type name |
||
31 | */ |
||
32 | 74 | public function getName() |
|
36 | |||
37 | 6 | public function resolveOfType(AbstractType $value) |
|
45 | |||
46 | 6 | public function resolveInputFields($value) |
|
55 | |||
56 | 5 | public function resolveEnumValues($value, $args) |
|
57 | { |
||
58 | /** @var $value AbstractType|AbstractEnumType */ |
||
59 | 5 | if ($value && $value->getKind() == TypeMap::KIND_ENUM) { |
|
60 | 5 | $data = []; |
|
61 | 5 | foreach ($value->getValues() as $enumValue) { |
|
62 | 5 | if(!$args['includeDeprecated'] && (isset($enumValue['isDeprecated']) && $enumValue['isDeprecated'])) { |
|
63 | continue; |
||
64 | } |
||
65 | |||
66 | 5 | if (!array_key_exists('description', $enumValue)) { |
|
67 | 5 | $enumValue['description'] = ''; |
|
68 | 5 | } |
|
69 | 5 | if (!array_key_exists('isDeprecated', $enumValue)) { |
|
70 | 5 | $enumValue['isDeprecated'] = false; |
|
71 | 5 | } |
|
72 | 5 | if (!array_key_exists('deprecationReason', $enumValue)) { |
|
73 | 5 | $enumValue['deprecationReason'] = null; |
|
74 | 5 | } |
|
75 | |||
76 | 5 | $data[] = $enumValue; |
|
77 | 5 | } |
|
78 | |||
79 | 5 | return $data; |
|
80 | } |
||
81 | |||
82 | 5 | return null; |
|
83 | } |
||
84 | |||
85 | 7 | public function resolveFields($value, $args) |
|
86 | { |
||
87 | /** @var AbstractType $value */ |
||
88 | 7 | if (!$value || |
|
89 | 7 | in_array($value->getKind(), [TypeMap::KIND_SCALAR, TypeMap::KIND_UNION, TypeMap::KIND_INPUT_OBJECT, TypeMap::KIND_ENUM]) |
|
90 | 7 | ) { |
|
91 | 6 | return null; |
|
92 | } |
||
93 | |||
94 | /** @var AbstractObjectType $value */ |
||
95 | 7 | return array_filter($value->getConfig()->getFields(), function ($field) use ($args) { |
|
96 | /** @var $field Field */ |
||
97 | 7 | if (in_array($field->getName(), ['__type', '__schema']) || (!$args['includeDeprecated'] && $field->isDeprecated())) { |
|
98 | 7 | return false; |
|
99 | } |
||
100 | |||
101 | 7 | return true; |
|
102 | 7 | }); |
|
103 | } |
||
104 | |||
105 | 6 | public function resolveInterfaces($value) |
|
115 | |||
116 | 6 | public function resolvePossibleTypes($value, $args, ResolveInfo $info) |
|
117 | { |
||
118 | /** @var $value AbstractObjectType */ |
||
119 | 6 | if ($value->getKind() == TypeMap::KIND_INTERFACE) { |
|
120 | 3 | $schema = $info->getExecutionContext()->getSchema(); |
|
121 | 3 | $this->collectTypes($schema->getQueryType()); |
|
122 | 3 | foreach ($schema->getTypesList()->getTypes() as $type) { |
|
123 | $this->collectTypes($type); |
||
124 | 3 | } |
|
125 | |||
126 | 3 | $possibleTypes = []; |
|
127 | 3 | foreach ($this->types as $type) { |
|
128 | /** @var $type AbstractObjectType */ |
||
129 | 3 | if ($type->getKind() == TypeMap::KIND_OBJECT) { |
|
130 | 3 | $interfaces = $type->getConfig()->getInterfaces(); |
|
131 | |||
132 | 3 | if ($interfaces) { |
|
133 | 3 | foreach ($interfaces as $interface) { |
|
134 | 3 | if ($interface->getName() == $value->getName()) { |
|
135 | 3 | $possibleTypes[] = $type; |
|
136 | 3 | } |
|
137 | 3 | } |
|
138 | 3 | } |
|
139 | 3 | } |
|
140 | 3 | } |
|
141 | |||
142 | 3 | return $possibleTypes; |
|
143 | 6 | } elseif ($value->getKind() == TypeMap::KIND_UNION) { |
|
144 | /** @var $value AbstractUnionType */ |
||
145 | 1 | return $value->getTypes(); |
|
146 | } |
||
147 | |||
148 | 6 | return null; |
|
149 | } |
||
150 | |||
151 | 11 | public function build($config) |
|
198 | |||
199 | } |
||
200 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: