Skip to content

Commit 493eabf

Browse files
Fixing calls to parent::parseLiteral()
1 parent 7914825 commit 493eabf

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,6 @@ public function dispatch(RequestInterface $request): ResponseInterface
211211
private function overrideStandardGraphQLTypes(): void
212212
{
213213
$standardTypes = GraphQLType::getStandardTypes();
214-
// $intConfig = [
215-
// 'name' => $standardInt->name,
216-
// 'description' => $standardInt->description,
217-
// 'astNode' => $standardInt->astNode,
218-
// 'extensionASTNodes' => $standardInt->extensionASTNodes
219-
// ];
220214

221215
$intType = new IntType($standardTypes[GraphQLType::INT]->config);
222216
$floatType = new FloatType($standardTypes[GraphQLType::FLOAT]->config);

lib/internal/Magento/Framework/GraphQl/Type/Definition/FloatType.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
use Exception;
1111
use GraphQL\Error\Error as GraphQLError;
12+
use GraphQL\Language\AST\FloatValueNode;
13+
use GraphQL\Language\AST\IntValueNode;
1214
use GraphQL\Language\AST\Node;
15+
use GraphQL\Language\AST\ValueNode;
1316

1417
/**
1518
* Replacement for the FloatType definition that can typecast non-numeric values for backwards compatibility
@@ -42,9 +45,19 @@ public function parseValue($value): float
4245
public function parseLiteral(Node $valueNode, ?array $variables = null): float
4346
{
4447
try {
45-
return $this->parseValue($valueNode->value);
48+
if (
49+
$valueNode instanceof ValueNode
50+
&& !($valueNode instanceof FloatValueNode)
51+
&& !($valueNode instanceof IntValueNode)
52+
&& isset($valueNode->value)
53+
) {
54+
$valueNode = new FloatValueNode([
55+
'value' => (string)$this->parseValue($valueNode->value),
56+
'loc' => $valueNode->loc
57+
]);
58+
}
4659
} catch (Exception $e) {
4760
}
48-
return parent::parseLiteral($valueNode);
61+
return parent::parseLiteral($valueNode, $variables);
4962
}
5063
}

lib/internal/Magento/Framework/GraphQl/Type/Definition/IntType.php

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

1010
use Exception;
1111
use GraphQL\Error\Error as GraphQLError;
12+
use GraphQL\Language\AST\IntValueNode;
1213
use GraphQL\Language\AST\Node;
14+
use GraphQL\Language\AST\ValueNode;
1315

1416
/**
1517
* Replacement for the IntType definition that can typecast non-numeric values for backwards compatibility
@@ -42,9 +44,18 @@ public function parseValue($value): int
4244
public function parseLiteral(Node $valueNode, ?array $variables = null): int
4345
{
4446
try {
45-
return $this->parseValue($valueNode->value);
47+
if (
48+
$valueNode instanceof ValueNode
49+
&& !($valueNode instanceof IntValueNode)
50+
&& isset($valueNode->value)
51+
) {
52+
$valueNode = new IntValueNode([
53+
'value' => (string)$this->parseValue($valueNode->value),
54+
'loc' => $valueNode->loc
55+
]);
56+
}
4657
} catch (Exception $e) {
4758
}
48-
return parent::parseLiteral($valueNode);
59+
return parent::parseLiteral($valueNode, $variables);
4960
}
5061
}

lib/internal/Magento/Framework/GraphQl/Type/Definition/StringType.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Exception;
1111
use GraphQL\Error\Error as GraphQLError;
1212
use GraphQL\Language\AST\Node;
13+
use GraphQL\Language\AST\StringValueNode;
14+
use GraphQL\Language\AST\ValueNode;
1315

1416
/**
1517
* Replacement for the StringType definition that can typecast non-string values for backwards compatibility
@@ -42,9 +44,18 @@ public function parseValue($value): string
4244
public function parseLiteral(Node $valueNode, ?array $variables = null): string
4345
{
4446
try {
45-
return $this->parseValue($valueNode->value);
47+
if (
48+
$valueNode instanceof ValueNode
49+
&& !($valueNode instanceof StringValueNode)
50+
&& isset($valueNode->value)
51+
) {
52+
$valueNode = new StringValueNode([
53+
'value' => $this->parseValue($valueNode->value),
54+
'loc' => $valueNode->loc
55+
]);
56+
}
4657
} catch (Exception $e) {
4758
}
48-
return parent::parseLiteral($valueNode);
59+
return parent::parseLiteral($valueNode, $variables);
4960
}
5061
}

0 commit comments

Comments
 (0)