attributeOptionsDataProvider = $attributeOptionsDataProvider; $this->valueFactory = $valueFactory; } /** * @inheritdoc */ public function resolve( Field $field, $context, ResolveInfo $info, array $value = null, array $args = null ) : Value { return $this->valueFactory->create(function () use ($value) { $entityType = $this->getEntityType($value); $attributeCode = $this->getAttributeCode($value); $optionsData = $this->getAttributeOptionsData($entityType, $attributeCode); return $optionsData; }); } /** * Get entity type * * @param array $value * @return int * @throws LocalizedException */ private function getEntityType(array $value): int { if (!isset($value['entity_type'])) { throw new LocalizedException(__('"Entity type should be specified')); } return (int)$value['entity_type']; } /** * Get attribute code * * @param array $value * @return string * @throws LocalizedException */ private function getAttributeCode(array $value): string { if (!isset($value['attribute_code'])) { throw new LocalizedException(__('"Attribute code should be specified')); } return $value['attribute_code']; } /** * Get attribute options data * * @param int $entityType * @param string $attributeCode * @return array * @throws GraphQlInputException * @throws GraphQlNoSuchEntityException */ private function getAttributeOptionsData(int $entityType, string $attributeCode): array { try { $optionsData = $this->attributeOptionsDataProvider->getData($entityType, $attributeCode); } catch (InputException $e) { throw new GraphQlInputException(__($e->getMessage()), $e); } catch (StateException $e) { throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); } return $optionsData; } }