Skip to content

Commit 3b194c4

Browse files
committed
Revert "LYNX-319 401 and 403 HTTP response codes for GraphQL API"
This reverts commit 8f401aa.
1 parent 11a4ea7 commit 3b194c4

File tree

7 files changed

+30
-357
lines changed

7 files changed

+30
-357
lines changed

app/code/Magento/CustomerGraphQl/Controller/HttpRequestValidator/AuthorizationRequestValidator.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

app/code/Magento/CustomerGraphQl/etc/graphql/di.xml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright 2024 Adobe
5-
* All Rights Reserved.
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
@@ -212,11 +212,4 @@
212212
<plugin name="merge_order_after_customer_signup"
213213
type="Magento\CustomerGraphQl\Plugin\Model\MergeGuestOrder" />
214214
</type>
215-
<type name="Magento\GraphQl\Controller\HttpRequestProcessor">
216-
<arguments>
217-
<argument name="requestValidators" xsi:type="array">
218-
<item name="authorizationValidator" xsi:type="object">Magento\CustomerGraphQl\Controller\HttpRequestValidator\AuthorizationRequestValidator</item>
219-
</argument>
220-
</arguments>
221-
</type>
222215
</config>

app/code/Magento/GraphQl/Controller/GraphQl.php

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
2+
23
/**
3-
* Copyright 2024 Adobe
4-
* All Rights Reserved.
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
56
*/
7+
68
declare(strict_types=1);
79

810
namespace Magento\GraphQl\Controller;
911

10-
use Exception;
1112
use Magento\Framework\App\Area;
1213
use Magento\Framework\App\AreaList;
1314
use Magento\Framework\App\FrontControllerInterface;
@@ -23,8 +24,6 @@
2324
use Magento\Framework\GraphQl\Query\QueryProcessor;
2425
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
2526
use Magento\Framework\GraphQl\Schema\SchemaGeneratorInterface;
26-
use Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException;
27-
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
2827
use Magento\Framework\Serialize\SerializerInterface;
2928
use Magento\Framework\Webapi\Response;
3029
use Magento\GraphQl\Helper\Query\Logger\LogData;
@@ -185,7 +184,7 @@ public function dispatch(RequestInterface $request): ResponseInterface
185184
$statusCode = 200;
186185
$jsonResult = $this->jsonFactory->create();
187186
$data = $this->getDataFromRequest($request);
188-
$result = ['errors' => []];
187+
$result = [];
189188

190189
$schema = null;
191190
$query = $data['query'] ?? '';
@@ -206,14 +205,8 @@ public function dispatch(RequestInterface $request): ResponseInterface
206205
$this->contextFactory->create(),
207206
$data['variables'] ?? []
208207
);
209-
$statusCode = $this->getHttpResponseCode($result);
210-
} catch (GraphQlAuthenticationException $error) {
211-
$result['errors'][] = $this->graphQlError->create($error);
212-
$statusCode = 401;
213-
} catch (GraphQlAuthorizationException $error) {
214-
$result['errors'][] = $this->graphQlError->create($error);
215-
$statusCode = 403;
216-
} catch (Exception $error) {
208+
} catch (\Exception $error) {
209+
$result['errors'] = isset($result['errors']) ? $result['errors'] : [];
217210
$result['errors'][] = $this->graphQlError->create($error);
218211
$statusCode = ExceptionFormatter::HTTP_GRAPH_QL_SCHEMA_ERROR_STATUS;
219212
}
@@ -223,7 +216,7 @@ public function dispatch(RequestInterface $request): ResponseInterface
223216
$jsonResult->renderResult($this->httpResponse);
224217

225218
// log information about the query, unless it is an introspection query
226-
if (!str_contains($query, 'IntrospectionQuery')) {
219+
if (strpos($query, 'IntrospectionQuery') === false) {
227220
$queryInformation = $this->logDataHelper->getLogData($request, $data, $schema, $this->httpResponse);
228221
$this->loggerPool->execute($queryInformation);
229222
}
@@ -254,30 +247,4 @@ private function getDataFromRequest(RequestInterface $request): array
254247

255248
return $data;
256249
}
257-
258-
/**
259-
* Retrieve http response code based on the error categories
260-
*
261-
* @param array $result
262-
* @return int
263-
*/
264-
private function getHttpResponseCode(array $result): int
265-
{
266-
if (empty($result['errors'])) {
267-
return 200;
268-
}
269-
foreach ($result['errors'] as $error) {
270-
if (!isset($error['extensions']['category'])) {
271-
continue;
272-
}
273-
switch ($error['extensions']['category']) {
274-
case GraphQlAuthenticationException::EXCEPTION_CATEGORY:
275-
return 401;
276-
case GraphQlAuthorizationException::EXCEPTION_CATEGORY:
277-
return 403;
278-
}
279-
}
280-
281-
return 200;
282-
}
283250
}

0 commit comments

Comments
 (0)