Skip to content

Commit 5d7ab6c

Browse files
authored
Merge pull request #33858 from anzin/improvments/ce-32863-update-webonyx-graphql-php-dependency
Updated webonyx/graphql-php to version 14.9.0
2 parents f0c22c9 + 51ceb50 commit 5d7ab6c

File tree

12 files changed

+95
-91
lines changed

12 files changed

+95
-91
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
namespace Magento\GraphQl\Controller\HttpRequestValidator;
99

10+
use GraphQL\Language\AST\Node;
11+
use GraphQL\Language\AST\NodeKind;
12+
use GraphQL\Language\Parser;
13+
use GraphQL\Language\Source;
14+
use GraphQL\Language\Visitor;
1015
use Magento\Framework\App\HttpRequestInterface;
11-
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1216
use Magento\Framework\App\Request\Http;
17+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
18+
use Magento\Framework\Phrase;
1319
use Magento\GraphQl\Controller\HttpRequestValidatorInterface;
14-
use GraphQL\Language\AST\Node;
15-
use GraphQL\Language\AST\NodeKind;
1620

1721
/**
1822
* Validator to check HTTP verb for Graphql requests
@@ -26,15 +30,15 @@ class HttpVerbValidator implements HttpRequestValidatorInterface
2630
* @return void
2731
* @throws GraphQlInputException
2832
*/
29-
public function validate(HttpRequestInterface $request) : void
33+
public function validate(HttpRequestInterface $request): void
3034
{
3135
/** @var Http $request */
3236
if (false === $request->isPost()) {
3337
$query = $request->getParam('query', '');
3438
if (!empty($query)) {
35-
$operationType = null;
36-
$queryAst = \GraphQL\Language\Parser::parse(new \GraphQL\Language\Source($query ?: '', 'GraphQL'));
37-
\GraphQL\Language\Visitor::visit(
39+
$operationType = '';
40+
$queryAst = Parser::parse(new Source($query ?: '', 'GraphQL'));
41+
Visitor::visit(
3842
$queryAst,
3943
[
4044
'leave' => [
@@ -47,7 +51,7 @@ public function validate(HttpRequestInterface $request) : void
4751

4852
if (strtolower($operationType) === 'mutation') {
4953
throw new GraphQlInputException(
50-
new \Magento\Framework\Phrase('Mutation requests allowed only for POST requests')
54+
new Phrase('Mutation requests allowed only for POST requests')
5155
);
5256
}
5357
}

app/code/Magento/GraphQl/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"magento/module-eav": "*",
88
"magento/framework": "*",
99
"magento/module-webapi": "*",
10-
"magento/module-authorization": "*"
10+
"magento/module-authorization": "*",
11+
"webonyx/graphql-php": "^14.9.0"
1112
},
1213
"suggest": {
1314
"magento/module-graph-ql-cache": "*"

app/code/Magento/GraphQlCache/Model/Plugin/Query/Resolver.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
use Magento\Framework\GraphQl\Config\Element\Field;
1111
use Magento\Framework\GraphQl\Query\ResolverInterface;
12-
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13-
use Magento\GraphQl\Model\Query\Resolver\Context;
1412
use Magento\Framework\GraphQl\Query\Resolver\Value;
1513
use Magento\GraphQlCache\Model\CacheableQueryHandler;
1614

@@ -39,21 +37,13 @@ public function __construct(
3937
* @param ResolverInterface $subject
4038
* @param mixed|Value $resolvedValue
4139
* @param Field $field
42-
* @param Context $context
43-
* @param ResolveInfo $info
44-
* @param array|null $value
45-
* @param array|null $args
4640
* @return mixed
4741
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4842
*/
4943
public function afterResolve(
5044
ResolverInterface $subject,
5145
$resolvedValue,
52-
Field $field,
53-
$context,
54-
ResolveInfo $info,
55-
array $value = null,
56-
array $args = null
46+
Field $field
5747
) {
5848
$cacheAnnotation = $field->getCache();
5949
if (!empty($cacheAnnotation)) {
@@ -62,19 +52,19 @@ public function afterResolve(
6252
$resolvedValue,
6353
$cacheAnnotation
6454
);
65-
} elseif ($resolvedValue instanceof \Magento\Framework\GraphQl\Query\Resolver\Value) {
55+
} elseif ($resolvedValue instanceof Value) {
6656
$resolvedValue->then(
6757
function () use ($resolvedValue, $field, $cacheAnnotation) {
68-
if (is_array($resolvedValue->promise->result)) {
58+
if (is_array($resolvedValue->result)) {
6959
$this->cacheableQueryHandler->handleCacheFromResolverResponse(
70-
$resolvedValue->promise->result,
60+
$resolvedValue->result,
7161
$cacheAnnotation
7262
);
7363
} else {
7464
// case if string or integer we pass in a single array element
7565
$this->cacheableQueryHandler->handleCacheFromResolverResponse(
76-
$resolvedValue->promise->result === null ?
77-
[] : [$field->getName() => $resolvedValue->promise->result],
66+
$resolvedValue->result === null ?
67+
[] : [$field->getName() => $resolvedValue->result],
7868
$cacheAnnotation
7969
);
8070
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"tedivm/jshrink": "~1.4.0",
7777
"tubalmartin/cssmin": "4.1.1",
7878
"web-token/jwt-framework": "^v2.2.7",
79-
"webonyx/graphql-php": "^0.13.8",
79+
"webonyx/graphql-php": "~14.9.0",
8080
"wikimedia/less.php": "^3.0.0"
8181
},
8282
"require-dev": {

composer.lock

Lines changed: 28 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/api-functional/testsuite/Magento/GraphQl/VariablesSupportQueryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testQueryObjectVariablesSupport()
4646
amount {
4747
value
4848
currency
49-
}
49+
}
5050
}
5151
}
5252
}
@@ -59,7 +59,7 @@ public function testQueryObjectVariablesSupport()
5959
'priceSort' => 'ASC',
6060
'filterInput' => [
6161
'price' => [
62-
'from' => 150,
62+
'from' => '150',
6363
],
6464
],
6565
];

dev/tests/integration/testsuite/Magento/GraphQlCache/Controller/Catalog/CategoriesWithProductsCacheTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ public function testRequestCacheTagsForCategoryWithProducts(): void
3131
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
3232
/** @var ProductInterface $product */
3333
$product = $productRepository->get('simple333');
34-
$categoryId ='333';
35-
$query
36-
= <<<QUERY
34+
$categoryId = 333;
35+
$query =
36+
<<<QUERY
3737
query GetCategoryWithProducts(\$id: Int!, \$pageSize: Int!, \$currentPage: Int!) {
3838
category(id: \$id) {
3939
id
4040
description
4141
name
4242
product_count
4343
products(
44-
pageSize: \$pageSize,
44+
pageSize: \$pageSize,
4545
currentPage: \$currentPage) {
4646
items {
4747
id
@@ -59,7 +59,7 @@ public function testRequestCacheTagsForCategoryWithProducts(): void
5959
}
6060
}
6161
QUERY;
62-
$variables =[
62+
$variables = [
6363
'id' => $categoryId,
6464
'pageSize'=> 10,
6565
'currentPage' => 1
@@ -72,7 +72,7 @@ public function testRequestCacheTagsForCategoryWithProducts(): void
7272

7373
$response = $this->dispatchGraphQlGETRequest($queryParams);
7474
$this->assertEquals('MISS', $response->getHeader('X-Magento-Cache-Debug')->getFieldValue());
75-
$expectedCacheTags = ['cat_c','cat_c_' . $categoryId,'cat_p','cat_p_' . $product->getId(),'FPC'];
75+
$expectedCacheTags = ['cat_c', 'cat_c_' . $categoryId, 'cat_p', 'cat_p_' . $product->getId(), 'FPC'];
7676
$actualCacheTags = explode(',', $response->getHeader('X-Magento-Tags')->getFieldValue());
7777
$this->assertEquals($expectedCacheTags, $actualCacheTags);
7878
}

lib/internal/Magento/Framework/GraphQl/Exception/ExceptionFormatter.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
namespace Magento\Framework\GraphQl\Exception;
99

10+
use Exception;
11+
use GraphQL\Error\DebugFlag;
12+
use GraphQL\Error\FormattedError;
1013
use Magento\Framework\App\State;
1114
use Magento\Framework\Webapi\ErrorProcessor;
1215
use Psr\Log\LoggerInterface;
16+
use Throwable;
1317

1418
/**
1519
* Wrapper for GraphQl Exception Formatter
@@ -31,6 +35,7 @@ class ExceptionFormatter
3135
/**
3236
* @param State $appState
3337
* @param ErrorProcessor $errorProcessor
38+
* @param LoggerInterface $logger
3439
*/
3540
public function __construct(State $appState, ErrorProcessor $errorProcessor, LoggerInterface $logger)
3641
{
@@ -45,25 +50,24 @@ public function __construct(State $appState, ErrorProcessor $errorProcessor, Log
4550
* This method only exposes exception message when exception implements ClientAware interface
4651
* (or when debug flags are passed).
4752
*
48-
* @param \Throwable $exception
49-
* @param string $internalErrorMessage
53+
* @param Throwable $exception
54+
* @param string|null $internalErrorMessage
5055
* @return array
51-
* @throws \Throwable
56+
* @throws Throwable
5257
*/
53-
public function create(\Throwable $exception, $internalErrorMessage = null) : array
58+
public function create(Throwable $exception, $internalErrorMessage = null): array
5459
{
5560
if (!$this->shouldShowDetail()) {
5661
$reportId = uniqid("graph-ql-");
5762
$message = "Report ID: {$reportId}; Message: {$exception->getMessage()}";
5863
$code = $exception->getCode();
59-
$loggedException = new \Exception($message, $code, $exception);
64+
$loggedException = new Exception($message, $code, $exception);
6065
$this->logger->critical($loggedException);
6166
}
6267

63-
return \GraphQL\Error\FormattedError::createFromException(
68+
return FormattedError::createFromException(
6469
$exception,
65-
$this->shouldShowDetail()
66-
? \GraphQL\Error\Debug::INCLUDE_DEBUG_MESSAGE | \GraphQL\Error\Debug::INCLUDE_TRACE : false,
70+
(int) ($this->shouldShowDetail() ? DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE : false),
6771
$internalErrorMessage
6872
);
6973
}
@@ -73,7 +77,7 @@ public function create(\Throwable $exception, $internalErrorMessage = null) : ar
7377
*
7478
* @return bool
7579
*/
76-
public function shouldShowDetail() : bool
80+
public function shouldShowDetail(): bool
7781
{
7882
return $this->appState->getMode() === State::MODE_DEVELOPER;
7983
}

0 commit comments

Comments
 (0)