|
3 | 3 | namespace GraphQL; |
4 | 4 |
|
5 | 5 | use GraphQL\Exception\ArgumentException; |
6 | | -use GraphQL\Exception\InvalidSelectionException; |
7 | 6 | use GraphQL\Exception\InvalidVariableException; |
8 | 7 | use GraphQL\Util\StringLiteralFormatter; |
9 | 8 |
|
|
14 | 13 | */ |
15 | 14 | class Query |
16 | 15 | { |
| 16 | + use FieldTrait; |
| 17 | + |
17 | 18 | /** |
18 | 19 | * Stores the GraphQL query format |
19 | 20 | * |
@@ -56,13 +57,6 @@ class Query |
56 | 57 | */ |
57 | 58 | protected $arguments; |
58 | 59 |
|
59 | | - /** |
60 | | - * Stores the selection set desired to get from the query, can include nested queries |
61 | | - * |
62 | | - * @var array |
63 | | - */ |
64 | | - protected $selectionSet; |
65 | | - |
66 | 60 | /** |
67 | 61 | * Private member that's not accessible from outside the class, used internally to deduce if query is nested or not |
68 | 62 | * |
@@ -144,28 +138,6 @@ public function setArguments(array $arguments): Query |
144 | 138 | return $this; |
145 | 139 | } |
146 | 140 |
|
147 | | - /** |
148 | | - * @param array $selectionSet |
149 | | - * |
150 | | - * @return Query |
151 | | - * @throws InvalidSelectionException |
152 | | - */ |
153 | | - public function setSelectionSet(array $selectionSet): Query |
154 | | - { |
155 | | - $nonStringsFields = array_filter($selectionSet, function($element) { |
156 | | - return !is_string($element) && !$element instanceof Query; |
157 | | - }); |
158 | | - if (!empty($nonStringsFields)) { |
159 | | - throw new InvalidSelectionException( |
160 | | - 'One or more of the selection fields provided is not of type string or Query' |
161 | | - ); |
162 | | - } |
163 | | - |
164 | | - $this->selectionSet = $selectionSet; |
165 | | - |
166 | | - return $this; |
167 | | - } |
168 | | - |
169 | 141 | /** |
170 | 142 | * @return string |
171 | 143 | */ |
@@ -232,35 +204,6 @@ protected function constructArguments(): string |
232 | 204 | return $constraintsString; |
233 | 205 | } |
234 | 206 |
|
235 | | - /** |
236 | | - * @return string |
237 | | - */ |
238 | | - protected function constructSelectionSet(): string |
239 | | - { |
240 | | - $attributesString = " {\n"; |
241 | | - $first = true; |
242 | | - foreach ($this->selectionSet as $attribute) { |
243 | | - |
244 | | - // Append empty line at the beginning if it's not the first item on the list |
245 | | - if ($first) { |
246 | | - $first = false; |
247 | | - } else { |
248 | | - $attributesString .= "\n"; |
249 | | - } |
250 | | - |
251 | | - // If query is included in attributes set as a nested query |
252 | | - if ($attribute instanceof Query) { |
253 | | - $attribute->setAsNested(); |
254 | | - } |
255 | | - |
256 | | - // Append attribute to returned attributes list |
257 | | - $attributesString .= $attribute; |
258 | | - } |
259 | | - $attributesString .= "\n}"; |
260 | | - |
261 | | - return $attributesString; |
262 | | - } |
263 | | - |
264 | 207 | /** |
265 | 208 | * @return string |
266 | 209 | */ |
|
0 commit comments