|
9 | 9 |
|
10 | 10 | use Magento\Catalog\Model\Product;
|
11 | 11 | use Magento\Framework\GraphQl\Config\Element\Field;
|
12 |
| -use Magento\Framework\GraphQl\Query\Resolver\Value; |
13 |
| -use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; |
| 12 | +use Magento\Framework\GraphQl\Exception\GraphQlInputException; |
14 | 13 | use Magento\Framework\GraphQl\Query\ResolverInterface;
|
15 | 14 | use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
|
16 | 15 | use Magento\Catalog\Helper\Output as OutputHelper;
|
|
20 | 19 | */
|
21 | 20 | class ProductHtmlAttribute implements ResolverInterface
|
22 | 21 | {
|
23 |
| - /** |
24 |
| - * @var ValueFactory |
25 |
| - */ |
26 |
| - private $valueFactory; |
27 |
| - |
28 | 22 | /**
|
29 | 23 | * @var OutputHelper
|
30 | 24 | */
|
31 | 25 | private $outputHelper;
|
32 | 26 |
|
33 | 27 | /**
|
34 |
| - * @param ValueFactory $valueFactory |
35 | 28 | * @param OutputHelper $outputHelper
|
36 | 29 | */
|
37 | 30 | public function __construct(
|
38 |
| - ValueFactory $valueFactory, |
39 | 31 | OutputHelper $outputHelper
|
40 | 32 | ) {
|
41 |
| - $this->valueFactory = $valueFactory; |
42 | 33 | $this->outputHelper = $outputHelper;
|
43 | 34 | }
|
44 | 35 |
|
45 | 36 | /**
|
46 |
| - * {@inheritdoc} |
| 37 | + * @inheritdoc |
47 | 38 | */
|
48 | 39 | public function resolve(
|
49 | 40 | Field $field,
|
50 | 41 | $context,
|
51 | 42 | ResolveInfo $info,
|
52 | 43 | array $value = null,
|
53 | 44 | array $args = null
|
54 |
| - ): Value { |
| 45 | + ) { |
55 | 46 | if (!isset($value['model'])) {
|
56 |
| - $result = function () { |
57 |
| - return null; |
58 |
| - }; |
59 |
| - return $this->valueFactory->create($result); |
| 47 | + throw new GraphQlInputException(__('"model" value should be specified')); |
60 | 48 | }
|
61 | 49 |
|
62 | 50 | /* @var $product Product */
|
63 | 51 | $product = $value['model'];
|
64 | 52 | $fieldName = $field->getName();
|
65 | 53 | $renderedValue = $this->outputHelper->productAttribute($product, $product->getData($fieldName), $fieldName);
|
66 |
| - $result = function () use ($renderedValue) { |
67 |
| - return $renderedValue; |
68 |
| - }; |
69 |
| - |
70 |
| - return $this->valueFactory->create($result); |
| 54 | + return $renderedValue; |
71 | 55 | }
|
72 | 56 | }
|
0 commit comments