Skip to content

Commit

Permalink
ENGCOM-2951: GraphQL modules delivery #179
Browse files Browse the repository at this point in the history
  • Loading branch information
Valeriy Naida authored Sep 11, 2018
2 parents 89d8f80 + 0c0dd9a commit fd37bff
Show file tree
Hide file tree
Showing 46 changed files with 556 additions and 907 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

namespace Magento\BundleGraphQl\Model\Resolver;

use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\BundleGraphQl\Model\Resolver\Links\Collection;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Framework\GraphQl\Query\ResolverInterface;

/**
* {@inheritdoc}
* @inheritdoc
*/
class BundleItemLinks implements ResolverInterface
{
Expand All @@ -42,16 +42,14 @@ public function __construct(
}

/**
* {@inheritDoc}
* @inheritdoc
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) : Value
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($value['option_id']) || !isset($value['parent_id'])) {
$result = function () {
return null;
};
return $this->valueFactory->create($result);
throw new GraphQlInputException(__('"option_id" and "parent_id" values should be specified'));
}

$this->linkCollection->addIdFilters((int)$value['option_id'], (int)$value['parent_id']);
$result = function () use ($value) {
return $this->linkCollection->getLinksForOptionId((int)$value['option_id']);
Expand Down
15 changes: 7 additions & 8 deletions app/code/Magento/BundleGraphQl/Model/Resolver/BundleItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Framework\GraphQl\Query\ResolverInterface;

/**
* {@inheritdoc}
* @inheritdoc
*/
class BundleItems implements ResolverInterface
{
Expand All @@ -35,31 +34,31 @@ class BundleItems implements ResolverInterface
/**
* @var MetadataPool
*/
private $metdataPool;
private $metadataPool;

/**
* @param Collection $bundleOptionCollection
* @param ValueFactory $valueFactory
* @param MetadataPool $metdataPool
* @param MetadataPool $metadataPool
*/
public function __construct(
Collection $bundleOptionCollection,
ValueFactory $valueFactory,
MetadataPool $metdataPool
MetadataPool $metadataPool
) {
$this->bundleOptionCollection = $bundleOptionCollection;
$this->valueFactory = $valueFactory;
$this->metdataPool = $metdataPool;
$this->metadataPool = $metadataPool;
}

/**
* Fetch and format bundle option items.
*
* {@inheritDoc}
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) : Value
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
$linkField = $this->metdataPool->getMetadata(ProductInterface::class)->getLinkField();
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
if ($value['type_id'] !== Type::TYPE_CODE
|| !isset($value[$linkField])
|| !isset($value[ProductInterface::SKU])
Expand Down
20 changes: 8 additions & 12 deletions app/code/Magento/BundleGraphQl/Model/Resolver/Options/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

namespace Magento\BundleGraphQl\Model\Resolver\Options;

use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Deferred\Product;
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Deferred\Product as ProductDataProvider;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Framework\GraphQl\Query\ResolverInterface;

Expand All @@ -19,42 +19,38 @@
*/
class Label implements ResolverInterface
{

/**
* @var ValueFactory
*/
private $valueFactory;

/**
* @var Product
* @var ProductDataProvider
*/
private $product;

/**
* @param ValueFactory $valueFactory
* @param Product $product
* @param ProductDataProvider $product
*/
public function __construct(ValueFactory $valueFactory, Product $product)
public function __construct(ValueFactory $valueFactory, ProductDataProvider $product)
{
$this->valueFactory = $valueFactory;
$this->product = $product;
}

/**
* @inheritDoc
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
): Value {
) {
if (!isset($value['sku'])) {
$result = function () {
return null;
};
return $this->valueFactory->create($result);
throw new GraphQlInputException(__('"sku" value should be specified'));
}

$this->product->addProductSku($value['sku']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,33 @@
*/
declare(strict_types=1);


namespace Magento\BundleGraphQl\Model\Resolver\Product\Fields;

use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Bundle\Model\Product\Type as Bundle;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Framework\GraphQl\Query\ResolverInterface;

/**
* {@inheritdoc}
* @inheritdoc
*/
class DynamicPrice implements ResolverInterface
{
/**
* @var ValueFactory
*/
private $valueFactory;

/**
* @param ValueFactory $valueFactory
*/
public function __construct(ValueFactory $valueFactory)
{
$this->valueFactory = $valueFactory;
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
): Value {
) {
$result = null;
if ($value['type_id'] === Bundle::TYPE_CODE) {
$result = isset($value['price_type']) ? !$value['price_type'] : null;
}

return $this->valueFactory->create(
function () use ($result) {
return $result;
}
);
return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,33 @@
*/
declare(strict_types=1);


namespace Magento\BundleGraphQl\Model\Resolver\Product\Fields;

use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Bundle\Model\Product\Type as Bundle;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Framework\GraphQl\Query\ResolverInterface;

/**
* {@inheritdoc}
* @inheritdoc
*/
class DynamicSku implements ResolverInterface
{
/**
* @var ValueFactory
*/
private $valueFactory;

/**
* @param ValueFactory $valueFactory
*/
public function __construct(ValueFactory $valueFactory)
{
$this->valueFactory = $valueFactory;
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
): Value {
$result = function () {
return null;
};
) {
$result = null;
if ($value['type_id'] === Bundle::TYPE_CODE) {
$result = isset($value['sku_type']) ? !$value['sku_type'] : null;
}

return $this->valueFactory->create(
function () use ($result) {
return $result;
}
);
return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,33 @@
*/
declare(strict_types=1);


namespace Magento\BundleGraphQl\Model\Resolver\Product\Fields;

use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Bundle\Model\Product\Type as Bundle;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Framework\GraphQl\Query\ResolverInterface;

/**
* {@inheritdoc}
* @inheritdoc
*/
class DynamicWeight implements ResolverInterface
{
/**
* @var ValueFactory
*/
private $valueFactory;

/**
* @param ValueFactory $valueFactory
*/
public function __construct(ValueFactory $valueFactory)
{
$this->valueFactory = $valueFactory;
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
): Value {
$result = function () {
return null;
};
) {
$result = null;
if ($value['type_id'] === Bundle::TYPE_CODE) {
$result = isset($value['weight_type']) ? !$value['weight_type'] : null;
}

return $this->valueFactory->create(
function () use ($result) {
return $result;
}
);
return $result;
}
}
Loading

0 comments on commit fd37bff

Please sign in to comment.