7
7
8
8
namespace Magento \Framework \GraphQl \Query ;
9
9
10
+ use Magento \Framework \Exception \RuntimeException ;
10
11
use Magento \Framework \GraphQl \Config \Element \Enum ;
11
12
use Magento \Framework \GraphQl \ConfigInterface ;
12
13
use Magento \Framework \GraphQl \Schema \Type \Enum \DataMapperInterface ;
14
+ use Magento \Framework \Phrase ;
13
15
14
16
/**
15
17
* Processor that looks up definition data of an enum to lookup and convert data as it's specified in the schema.
@@ -27,8 +29,6 @@ class EnumLookup
27
29
private $ enumDataMapper ;
28
30
29
31
/**
30
- * EnumLookup constructor.
31
- *
32
32
* @param ConfigInterface $typeConfig
33
33
* @param DataMapperInterface $enumDataMapper
34
34
*/
@@ -44,11 +44,19 @@ public function __construct(ConfigInterface $typeConfig, DataMapperInterface $en
44
44
* @param string $enumName
45
45
* @param string $fieldValue
46
46
* @return string
47
+ * @throws RuntimeException
47
48
*/
48
49
public function getEnumValueFromField (string $ enumName , string $ fieldValue ) : string
49
50
{
50
51
/** @var Enum $enumObject */
51
52
$ enumObject = $ this ->typeConfig ->getConfigElement ($ enumName );
53
+
54
+ if (!($ enumObject instanceof Enum)) {
55
+ throw new RuntimeException (
56
+ new Phrase ('Enum type "%1" not defined ' , [$ enumName ])
57
+ );
58
+ }
59
+
52
60
$ mappedValues = $ this ->enumDataMapper ->getMappedEnums ($ enumName );
53
61
54
62
foreach ($ enumObject ->getValues () as $ enumItem ) {
0 commit comments