Skip to content

Commit 8984c54

Browse files
author
Valeriy Nayda
committed
GraphQL-152: Allow scalars as resolver return type
1 parent 61fb87f commit 8984c54

File tree

43 files changed

+248
-904
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+248
-904
lines changed

app/code/Magento/BundleGraphQl/Model/Resolver/BundleItemLinks.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
namespace Magento\BundleGraphQl\Model\Resolver;
99

10+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1011
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1112
use Magento\BundleGraphQl\Model\Resolver\Links\Collection;
1213
use Magento\Framework\GraphQl\Config\Element\Field;
13-
use Magento\Framework\GraphQl\Query\Resolver\Value;
1414
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
1515
use Magento\Framework\GraphQl\Query\ResolverInterface;
1616

1717
/**
18-
* {@inheritdoc}
18+
* @inheritdoc
1919
*/
2020
class BundleItemLinks implements ResolverInterface
2121
{
@@ -42,16 +42,14 @@ public function __construct(
4242
}
4343

4444
/**
45-
* {@inheritDoc}
45+
* @inheritdoc
4646
*/
47-
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) : Value
47+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
4848
{
4949
if (!isset($value['option_id']) || !isset($value['parent_id'])) {
50-
$result = function () {
51-
return null;
52-
};
53-
return $this->valueFactory->create($result);
50+
throw new GraphQlInputException(__('"option_id" and "parent_id" values should be specified'));
5451
}
52+
5553
$this->linkCollection->addIdFilters((int)$value['option_id'], (int)$value['parent_id']);
5654
$result = function () use ($value) {
5755
return $this->linkCollection->getLinksForOptionId((int)$value['option_id']);

app/code/Magento/BundleGraphQl/Model/Resolver/BundleItems.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
use Magento\Catalog\Api\Data\ProductInterface;
1414
use Magento\Framework\EntityManager\MetadataPool;
1515
use Magento\Framework\GraphQl\Config\Element\Field;
16-
use Magento\Framework\GraphQl\Query\Resolver\Value;
1716
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
1817
use Magento\Framework\GraphQl\Query\ResolverInterface;
1918

2019
/**
21-
* {@inheritdoc}
20+
* @inheritdoc
2221
*/
2322
class BundleItems implements ResolverInterface
2423
{
@@ -35,7 +34,7 @@ class BundleItems implements ResolverInterface
3534
/**
3635
* @var MetadataPool
3736
*/
38-
private $metdataPool;
37+
private $metadataPool;
3938

4039
/**
4140
* @param Collection $bundleOptionCollection
@@ -57,9 +56,9 @@ public function __construct(
5756
*
5857
* {@inheritDoc}
5958
*/
60-
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) : Value
59+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
6160
{
62-
$linkField = $this->metdataPool->getMetadata(ProductInterface::class)->getLinkField();
61+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
6362
if ($value['type_id'] !== Type::TYPE_CODE
6463
|| !isset($value[$linkField])
6564
|| !isset($value[ProductInterface::SKU])

app/code/Magento/BundleGraphQl/Model/Resolver/Options/Label.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
namespace Magento\BundleGraphQl\Model\Resolver\Options;
99

10+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1011
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
11-
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Deferred\Product;
12+
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Deferred\Product as ProductDataProvider;
1213
use Magento\Framework\GraphQl\Config\Element\Field;
13-
use Magento\Framework\GraphQl\Query\Resolver\Value;
1414
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
1515
use Magento\Framework\GraphQl\Query\ResolverInterface;
1616

@@ -19,42 +19,38 @@
1919
*/
2020
class Label implements ResolverInterface
2121
{
22-
2322
/**
2423
* @var ValueFactory
2524
*/
2625
private $valueFactory;
2726

2827
/**
29-
* @var Product
28+
* @var ProductDataProvider
3029
*/
3130
private $product;
3231

3332
/**
3433
* @param ValueFactory $valueFactory
35-
* @param Product $product
34+
* @param ProductDataProvider $product
3635
*/
37-
public function __construct(ValueFactory $valueFactory, Product $product)
36+
public function __construct(ValueFactory $valueFactory, ProductDataProvider $product)
3837
{
3938
$this->valueFactory = $valueFactory;
4039
$this->product = $product;
4140
}
4241

4342
/**
44-
* @inheritDoc
43+
* @inheritdoc
4544
*/
4645
public function resolve(
4746
Field $field,
4847
$context,
4948
ResolveInfo $info,
5049
array $value = null,
5150
array $args = null
52-
): Value {
51+
) {
5352
if (!isset($value['sku'])) {
54-
$result = function () {
55-
return null;
56-
};
57-
return $this->valueFactory->create($result);
53+
throw new GraphQlInputException(__('"sku" value should be specified'));
5854
}
5955

6056
$this->product->addProductSku($value['sku']);

app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicPrice.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,33 @@
55
*/
66
declare(strict_types=1);
77

8-
98
namespace Magento\BundleGraphQl\Model\Resolver\Product\Fields;
109

1110
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1211
use Magento\Bundle\Model\Product\Type as Bundle;
1312
use Magento\Framework\GraphQl\Config\Element\Field;
14-
use Magento\Framework\GraphQl\Query\Resolver\Value;
15-
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
1613
use Magento\Framework\GraphQl\Query\ResolverInterface;
1714

1815
/**
19-
* {@inheritdoc}
16+
* @inheritdoc
2017
*/
2118
class DynamicPrice implements ResolverInterface
2219
{
2320
/**
24-
* @var ValueFactory
25-
*/
26-
private $valueFactory;
27-
28-
/**
29-
* @param ValueFactory $valueFactory
30-
*/
31-
public function __construct(ValueFactory $valueFactory)
32-
{
33-
$this->valueFactory = $valueFactory;
34-
}
35-
36-
/**
37-
* {@inheritdoc}
21+
* @inheritdoc
3822
*/
3923
public function resolve(
4024
Field $field,
4125
$context,
4226
ResolveInfo $info,
4327
array $value = null,
4428
array $args = null
45-
): Value {
29+
) {
4630
$result = null;
4731
if ($value['type_id'] === Bundle::TYPE_CODE) {
4832
$result = isset($value['price_type']) ? !$value['price_type'] : null;
4933
}
5034

51-
return $this->valueFactory->create(
52-
function () use ($result) {
53-
return $result;
54-
}
55-
);
35+
return $result;
5636
}
5737
}

app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicSku.php

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,33 @@
55
*/
66
declare(strict_types=1);
77

8-
98
namespace Magento\BundleGraphQl\Model\Resolver\Product\Fields;
109

1110
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1211
use Magento\Bundle\Model\Product\Type as Bundle;
1312
use Magento\Framework\GraphQl\Config\Element\Field;
14-
use Magento\Framework\GraphQl\Query\Resolver\Value;
15-
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
1613
use Magento\Framework\GraphQl\Query\ResolverInterface;
1714

1815
/**
19-
* {@inheritdoc}
16+
* @inheritdoc
2017
*/
2118
class DynamicSku implements ResolverInterface
2219
{
2320
/**
24-
* @var ValueFactory
25-
*/
26-
private $valueFactory;
27-
28-
/**
29-
* @param ValueFactory $valueFactory
30-
*/
31-
public function __construct(ValueFactory $valueFactory)
32-
{
33-
$this->valueFactory = $valueFactory;
34-
}
35-
36-
/**
37-
* {@inheritdoc}
21+
* @inheritdoc
3822
*/
3923
public function resolve(
4024
Field $field,
4125
$context,
4226
ResolveInfo $info,
4327
array $value = null,
4428
array $args = null
45-
): Value {
46-
$result = function () {
47-
return null;
48-
};
29+
) {
30+
$result = null;
4931
if ($value['type_id'] === Bundle::TYPE_CODE) {
5032
$result = isset($value['sku_type']) ? !$value['sku_type'] : null;
5133
}
5234

53-
return $this->valueFactory->create(
54-
function () use ($result) {
55-
return $result;
56-
}
57-
);
35+
return $result;
5836
}
5937
}

app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicWeight.php

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,33 @@
55
*/
66
declare(strict_types=1);
77

8-
98
namespace Magento\BundleGraphQl\Model\Resolver\Product\Fields;
109

1110
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1211
use Magento\Bundle\Model\Product\Type as Bundle;
1312
use Magento\Framework\GraphQl\Config\Element\Field;
14-
use Magento\Framework\GraphQl\Query\Resolver\Value;
15-
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
1613
use Magento\Framework\GraphQl\Query\ResolverInterface;
1714

1815
/**
19-
* {@inheritdoc}
16+
* @inheritdoc
2017
*/
2118
class DynamicWeight implements ResolverInterface
2219
{
2320
/**
24-
* @var ValueFactory
25-
*/
26-
private $valueFactory;
27-
28-
/**
29-
* @param ValueFactory $valueFactory
30-
*/
31-
public function __construct(ValueFactory $valueFactory)
32-
{
33-
$this->valueFactory = $valueFactory;
34-
}
35-
36-
/**
37-
* {@inheritdoc}
21+
* @inheritdoc
3822
*/
3923
public function resolve(
4024
Field $field,
4125
$context,
4226
ResolveInfo $info,
4327
array $value = null,
4428
array $args = null
45-
): Value {
46-
$result = function () {
47-
return null;
48-
};
29+
) {
30+
$result = null;
4931
if ($value['type_id'] === Bundle::TYPE_CODE) {
5032
$result = isset($value['weight_type']) ? !$value['weight_type'] : null;
5133
}
5234

53-
return $this->valueFactory->create(
54-
function () use ($result) {
55-
return $result;
56-
}
57-
);
35+
return $result;
5836
}
5937
}

app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/PriceView.php

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@
55
*/
66
declare(strict_types=1);
77

8-
98
namespace Magento\BundleGraphQl\Model\Resolver\Product\Fields;
109

1110
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1211
use Magento\Bundle\Model\Product\Type as Bundle;
1312
use Magento\Framework\GraphQl\Config\Element\Field;
1413
use Magento\Framework\GraphQl\Query\EnumLookup;
15-
use Magento\Framework\GraphQl\Query\Resolver\Value;
16-
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
1714
use Magento\Framework\GraphQl\Query\ResolverInterface;
1815

1916
/**
20-
* {@inheritdoc}
17+
* @inheritdoc
2118
*/
2219
class PriceView implements ResolverInterface
2320
{
@@ -26,43 +23,30 @@ class PriceView implements ResolverInterface
2623
*/
2724
private $enumLookup;
2825

29-
/**
30-
* @var ValueFactory
31-
*/
32-
private $valueFactory;
33-
3426
/**
3527
* @param EnumLookup $enumLookup
36-
* @param ValueFactory $valueFactory
3728
*/
38-
public function __construct(EnumLookup $enumLookup, ValueFactory $valueFactory)
29+
public function __construct(EnumLookup $enumLookup)
3930
{
4031
$this->enumLookup = $enumLookup;
41-
$this->valueFactory = $valueFactory;
4232
}
4333

4434
/**
45-
* {@inheritdoc}
35+
* @inheritdoc
4636
*/
4737
public function resolve(
4838
Field $field,
4939
$context,
5040
ResolveInfo $info,
5141
array $value = null,
5242
array $args = null
53-
): Value {
54-
$result = function () {
55-
return null;
56-
};
43+
) {
44+
$result = null;
5745
if ($value['type_id'] === Bundle::TYPE_CODE) {
5846
$result = isset($value['price_view'])
5947
? $this->enumLookup->getEnumValueFromField('PriceViewEnum', $value['price_view']) : null;
6048
}
6149

62-
return $this->valueFactory->create(
63-
function () use ($result) {
64-
return $result;
65-
}
66-
);
50+
return $result;
6751
}
6852
}

0 commit comments

Comments
 (0)