Skip to content

Commit

Permalink
ENGCOM-2951: GraphQL modules delivery #179
Browse files Browse the repository at this point in the history
 - Merge Pull Request magento/graphql-ce#179 from magento/graphql-ce:GraphQL-172
 - Merged commits:
   1. 55387bd
   2. 5b11b8e
   3. 6e78ca6
   4. f8d1c29
   5. 06267e6
   6. f34f015
   7. 8984c54
   8. 5fdbfc0
   9. ecf79eb
   10. 4793553
   11. 39fd0f9
   12. 9186372
  • Loading branch information
magento-engcom-team committed Sep 11, 2018
2 parents 0eb8677 + 9186372 commit 0c0dd9a
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 0c0dd9a

Please sign in to comment.