|
1 | 1 | <?php
|
2 |
| - |
3 | 2 | /**
|
4 |
| - * Copyright © Magento, Inc. All rights reserved. |
5 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2017 Adobe |
| 4 | + * All Rights Reserved. |
6 | 5 | */
|
7 |
| - |
8 | 6 | declare(strict_types=1);
|
9 | 7 |
|
10 | 8 | namespace Magento\GraphQl\Controller;
|
@@ -181,38 +179,44 @@ public function dispatch(RequestInterface $request): ResponseInterface
|
181 | 179 | {
|
182 | 180 | $this->areaList->getArea(Area::AREA_GRAPHQL)->load(Area::PART_TRANSLATE);
|
183 | 181 |
|
184 |
| - $statusCode = 200; |
| 182 | + $statusCode = 204; |
185 | 183 | $jsonResult = $this->jsonFactory->create();
|
186 | 184 | $data = $this->getDataFromRequest($request);
|
187 |
| - $result = []; |
| 185 | + $result = null; |
188 | 186 |
|
189 | 187 | $schema = null;
|
190 | 188 | $query = $data['query'] ?? '';
|
191 | 189 | try {
|
192 | 190 | /** @var Http $request */
|
193 | 191 | $this->requestProcessor->validateRequest($request);
|
194 |
| - $parsedQuery = $this->queryParser->parse($query); |
195 |
| - $data['parsedQuery'] = $parsedQuery; |
196 |
| - |
197 |
| - // We must extract queried field names to avoid instantiation of unnecessary fields in webonyx schema |
198 |
| - // Temporal coupling is required for performance optimization |
199 |
| - $this->queryFields->setQuery($parsedQuery, $data['variables'] ?? null); |
200 |
| - $schema = $this->schemaGenerator->generate(); |
201 |
| - |
202 |
| - $result = $this->queryProcessor->process( |
203 |
| - $schema, |
204 |
| - $parsedQuery, |
205 |
| - $this->contextFactory->create(), |
206 |
| - $data['variables'] ?? [] |
207 |
| - ); |
| 192 | + if ($request->isGet() || $request->isPost()) { |
| 193 | + $parsedQuery = $this->queryParser->parse($query); |
| 194 | + $data['parsedQuery'] = $parsedQuery; |
| 195 | + |
| 196 | + // We must extract queried field names to avoid instantiation of unnecessary fields in webonyx schema |
| 197 | + // Temporal coupling is required for performance optimization |
| 198 | + $this->queryFields->setQuery($parsedQuery, $data['variables'] ?? null); |
| 199 | + $schema = $this->schemaGenerator->generate(); |
| 200 | + |
| 201 | + $result = $this->queryProcessor->process( |
| 202 | + $schema, |
| 203 | + $parsedQuery, |
| 204 | + $this->contextFactory->create(), |
| 205 | + $data['variables'] ?? [] |
| 206 | + ); |
| 207 | + $statusCode = 200; |
| 208 | + } |
208 | 209 | } catch (\Exception $error) {
|
209 |
| - $result['errors'] = isset($result['errors']) ? $result['errors'] : []; |
210 |
| - $result['errors'][] = $this->graphQlError->create($error); |
| 210 | + $result = [ |
| 211 | + 'errors' => [$this->graphQlError->create($error)], |
| 212 | + ]; |
211 | 213 | $statusCode = ExceptionFormatter::HTTP_GRAPH_QL_SCHEMA_ERROR_STATUS;
|
212 | 214 | }
|
213 | 215 |
|
214 | 216 | $jsonResult->setHttpResponseCode($statusCode);
|
215 |
| - $jsonResult->setData($result); |
| 217 | + if ($result !== null) { |
| 218 | + $jsonResult->setData($result); |
| 219 | + } |
216 | 220 | $jsonResult->renderResult($this->httpResponse);
|
217 | 221 |
|
218 | 222 | // log information about the query, unless it is an introspection query
|
|
0 commit comments