Skip to content

Commit 301ae4d

Browse files
committed
PWA-1611: Add operation status to DeleteNegotiableQuotesOutput
* Added base GraphQL error TypeResolver
1 parent 63d2866 commit 301ae4d

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Model\Mutation\Resolver;
9+
10+
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
11+
12+
/**
13+
* @inheritdoc
14+
*/
15+
class ErrorTypeResolver implements TypeResolverInterface
16+
{
17+
/**
18+
* Array of recognized errors for mutation operations.
19+
*
20+
* @var string[]
21+
*/
22+
private $validErrorTypes;
23+
24+
/**
25+
* @param string[] $validErrorTypes
26+
*/
27+
public function __construct(array $validErrorTypes)
28+
{
29+
$this->validErrorTypes = $validErrorTypes;
30+
}
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function resolveType(array $data): string
36+
{
37+
if (isset($data['error_type']) && in_array($data['error_type'], $this->validErrorTypes)) {
38+
$errorType = $data['error_type'];
39+
} else {
40+
$errorType = 'InternalError';
41+
}
42+
43+
return $errorType;
44+
}
45+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@
3030
</argument>
3131
</arguments>
3232
</type>
33+
<type name="Magento\GraphQl\Model\Mutation\Resolver\ErrorTypeResolver">
34+
<arguments>
35+
<argument name="validErrorTypes" xsi:type="array">
36+
<item name="no_such_entity_uid" xsi:type="string">NoSuchEntityUidError</item>
37+
<item name="internal_error" xsi:type="string">InternalError</item>
38+
</argument>
39+
</arguments>
40+
</type>
3341
</config>

app/code/Magento/GraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ enum BatchMutationStatus {
289289
MIXED_RESULTS
290290
}
291291

292-
interface ErrorInterface {
292+
interface ErrorInterface @typeResolver(class: "\\Magento\\GraphQl\\Model\\Mutation\\Resolver\\ErrorTypeResolver") {
293293
message: String!
294294
}
295295

0 commit comments

Comments
 (0)