Skip to content

Commit 476f14f

Browse files
author
vitaliyboyko
committed
graphQl-44: refactoring of resolver
Signed-off-by: vitaliyboyko <v.boyko@atwix.com>
1 parent a098fe5 commit 476f14f

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
use Magento\Catalog\Model\Product;
1111
use Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextAttribute\FormatList;
1212
use Magento\Framework\GraphQl\Config\Element\Field;
13-
use Magento\Framework\GraphQl\Query\Resolver\Value;
14-
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
13+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1514
use Magento\Framework\GraphQl\Query\ResolverInterface;
1615
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1716

@@ -25,26 +24,18 @@ class ProductTextAttribute implements ResolverInterface
2524
*/
2625
private $formatList;
2726

28-
/**
29-
* @var ValueFactory
30-
*/
31-
private $valueFactory;
32-
3327
/**
3428
* @var string
3529
*/
3630
private $defaultFormat = 'html';
3731

3832
/**
39-
* @param ValueFactory $valueFactory
40-
* @param FormatList $formatFactory
33+
* @param FormatList $formatList
4134
*/
4235
public function __construct(
43-
ValueFactory $valueFactory,
44-
FormatList $formatFactory
36+
FormatList $formatList
4537
) {
46-
$this->valueFactory = $valueFactory;
47-
$this->formatList = $formatFactory;
38+
$this->formatList = $formatList;
4839
}
4940

5041
/**
@@ -56,10 +47,9 @@ public function resolve(
5647
ResolveInfo $info,
5748
array $value = null,
5849
array $args = null
59-
): Value {
50+
) {
6051
if (!isset($value['model'])) {
61-
$result = [];
62-
return $this->valueFactory->create($result);
52+
throw new GraphQlInputException(__('"model" value should be specified'));
6353
}
6454

6555
/* @var $product Product */
@@ -69,6 +59,6 @@ public function resolve(
6959
$format = $this->formatList->create($formatIdentifier);
7060
$result = ['content' => $format->getContent($product, $fieldName)];
7161

72-
return $this->valueFactory->create($result);
62+
return $result;
7363
}
7464
}

0 commit comments

Comments
 (0)