File tree Expand file tree Collapse file tree 3 files changed +54
-1
lines changed Expand file tree Collapse file tree 3 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments