typeConfig = $typeConfig; $this->enumDataMapper = $enumDataMapper; } /** * Convert a field value from a db query to an enum value declared as an item in the graphql schema * * @param string $enumName * @param string $fieldValue * @return string * @throws \Magento\Framework\Exception\RuntimeException */ public function getEnumValueFromField(string $enumName, string $fieldValue) : string { $priceViewEnum = $this->typeConfig->getConfigElement($enumName); if ($priceViewEnum instanceof Enum) { foreach ($priceViewEnum->getValues() as $enumItem) { $mappedValues = $this->enumDataMapper->getMappedEnums($enumName); if (isset($mappedValues[$enumItem->getName()]) && $mappedValues[$enumItem->getName()] == $fieldValue) { return $enumItem->getValue(); } } } else { throw new \Magento\Framework\Exception\RuntimeException( new Phrase('Enum type "%1" not defined', [$enumName]) ); } return ''; } }