Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

GraphQL modules delivery #166

Merged
merged 72 commits into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a617b80
#31 Inited a new module and implement a basic support of CMS page ent…
Jun 30, 2018
94c904e
#31 Removed ID from array
Jun 30, 2018
9b26913
#31 Made it possible to return active pages only
Jun 30, 2018
e17c536
#32 Inited a new graph QL module that enables support of CMS blocks API
Jun 30, 2018
a7f0871
#32 Changed exception to throw
Jun 30, 2018
1f9c09e
#31 Refactored the code & committed composer.lock
Jun 30, 2018
0e2a2a6
#32 Refactored the code
Jun 30, 2018
85e6826
#31 Refactored module
Jun 30, 2018
c776df6
#32 Fixed code styling
Jul 2, 2018
f35af8b
#31 Refactored the code
Jul 2, 2018
5074178
#32 Added strict typing to bootstrap file
Jul 14, 2018
48fa7b5
#31 Fixed typo
Jul 14, 2018
5552cdc
#31 Removed the line
Jul 14, 2018
874f564
Merge remote-tracking branch 'origin/2.3-develop' into 31-cms-page-gr…
Jul 17, 2018
ad25c62
Empty cart creation mutation added
rogyar Jul 17, 2018
a182123
An empty line added
rogyar Jul 17, 2018
6789fe7
Return product stock data
bartekszymanski Jul 18, 2018
d2b9d53
Return product stock data
bartekszymanski Jul 18, 2018
98d27f3
Return product stock data
bartekszymanski Jul 18, 2018
a28ab2f
Return product stock data - Code Rewiev FIX
bartekszymanski Jul 18, 2018
67b4361
Return product stock data - Code Review FIX
bartekszymanski Jul 18, 2018
b9515e5
Return product stock data - Code Rewiev FIX
bartekszymanski Jul 18, 2018
0bdf075
Return product stock data - composer.json
bartekszymanski Jul 18, 2018
6847178
Return product stock data - composer.lock
bartekszymanski Jul 18, 2018
eb1ed7a
GraphQL-31: CMS page coverage
Jul 19, 2018
3bdd690
Merge branch '31-cms-page-graphql-support' into 32-cms-block-graphql-…
Jul 19, 2018
02ab4bf
GraphQL-32: CMS block coverage
Jul 19, 2018
dce6c11
Merge pull request #109 from magento/32-cms-block-graphql-support
Jul 19, 2018
c870ee8
Return product stock data - strict_types
bartekszymanski Jul 19, 2018
7a9b5bd
#31 Made it possible to return rendered content of CMS entities
Jul 24, 2018
1f2e6fa
#31 Imported dependencies
Jul 24, 2018
0ef53fd
Quote GraphQL module is added to the root composer.json
rogyar Jul 26, 2018
a62af8e
Readme and composer config adjustments
rogyar Jul 31, 2018
4a4baf2
Merge 2.3-develop into graphql-23
Aug 2, 2018
141c920
Return hashed cart id for both cases: logged in customer and guest
rogyar Aug 5, 2018
fcd809e
Optimized usage of user context
rogyar Aug 5, 2018
348e9b8
Added quote dependency
rogyar Aug 5, 2018
52f7069
updating composer.lock file
rogyar Aug 5, 2018
131d1e4
Removed authorization module dependency after recent optimizations
rogyar Aug 5, 2018
0beed4e
Merge branch '2.3-develop' into mutations-empty-cart
rogyar Aug 9, 2018
09ed1b8
Inject user context instead of using global implementation
rogyar Aug 9, 2018
dacd786
GraphQL-31: CMS page coverage
Aug 9, 2018
3eeb28f
Merge remote-tracking branch 'origin/2.3-develop' into 31-cms-page-gr…
Aug 9, 2018
8fe1e21
Api-functional tests added
rogyar Aug 10, 2018
4a8637f
Merge remote-tracking branch 'origin/2.3-develop' into graphql-23
Aug 13, 2018
23567bc
GraphQL-31: CMS page coverage
Aug 13, 2018
c5ecc0c
Merge remote-tracking branch 'origin/2.3-develop' into 31-cms-page-gr…
Aug 13, 2018
68fafd7
GraphQL-31: CMS page coverage
Aug 13, 2018
48ad892
GraphQL-125: Return product stock data
Aug 13, 2018
6f05267
Merge remote-tracking branch 'origin/2.3-develop' into graphql-23
Aug 14, 2018
51d5cea
GraphQL-125: Return product stock data
Aug 14, 2018
4016812
Merge remote-tracking branch 'origin/2.3-develop' into 31-cms-page-gr…
Aug 14, 2018
01c5a3d
GraphQL-31: CMS page coverage
Aug 14, 2018
0091c4e
Merge remote-tracking branch 'origin/2.3-develop' into 31-cms-page-gr…
Aug 15, 2018
171d40d
Merge remote-tracking branch 'origin/2.3-develop' into graphql-23
Aug 16, 2018
122fc46
Merge remote-tracking branch 'origin/2.3-develop' into 31-cms-page-gr…
Aug 17, 2018
8ac4471
GraphQL-31: CMS page coverage
Aug 17, 2018
3176de0
Introduced API for working with quote masked id
rogyar Aug 21, 2018
7ee4000
Merge remote-tracking branch 'origin/2.3-develop' into 31-cms-page-gr…
Aug 27, 2018
709a1f7
GraphQL-31: CMS page coverage
Aug 27, 2018
2966ac3
GraphQL-31: CMS page coverage
Aug 27, 2018
439df24
GraphQL-118: [Mutations] Cart Operations > Create Empty Cart
Sep 3, 2018
9bff89e
Merge remote-tracking branch 'origin/31-cms-page-graphql-support' int…
Sep 3, 2018
5c29598
Merge remote-tracking branch 'origin/mutations-empty-cart' into Graph…
Sep 3, 2018
b06aa33
Merge remote-tracking branch 'origin/graphql-23' into GraphQL-165
Sep 3, 2018
47d2aed
GraphQL-165: GraphQL modules delivery
Sep 3, 2018
bf98d4f
GraphQL-165: GraphQL modules delivery
Sep 3, 2018
277d542
GraphQL-165: GraphQL modules delivery
Sep 3, 2018
f8a3818
GraphQL-165: GraphQL modules delivery
Sep 3, 2018
6adb264
GraphQL-165: GraphQL modules delivery
Sep 3, 2018
32c73ce
GraphQL-165: GraphQL modules delivery
Sep 4, 2018
4098a38
GraphQL-152: Allow scalars as resolver return type
Sep 4, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogInventoryGraphQl\Model\Resolver;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogInventory\Api\StockRegistryInterface;
use Magento\CatalogInventory\Model\Configuration;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
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;
use Magento\Store\Model\ScopeInterface;

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

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @var StockRegistryInterface
*/
private $stockRegistry;

/**
* @param ValueFactory $valueFactory
* @param ScopeConfigInterface $scopeConfig
* @param StockRegistryInterface $stockRegistry
*/
public function __construct(
ValueFactory $valueFactory,
ScopeConfigInterface $scopeConfig,
StockRegistryInterface $stockRegistry
) {
$this->valueFactory = $valueFactory;
$this->scopeConfig = $scopeConfig;
$this->stockRegistry = $stockRegistry;
}

/**
* {@inheritdoc}
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null): Value
{
if (!array_key_exists('model', $value) || !$value['model'] instanceof ProductInterface) {
$result = function () {
return null;
};

return $this->valueFactory->create($result);
}

/* @var $product ProductInterface */
$product = $value['model'];
$onlyXLeftQty = $this->getOnlyXLeftQty($product);

$result = function () use ($onlyXLeftQty) {
return $onlyXLeftQty;
};

return $this->valueFactory->create($result);
}

/**
* Get product qty left when "Catalog > Inventory > Stock Options > Only X left Threshold" is greater than 0
*
* @param ProductInterface $product
*
* @return null|float
*/
private function getOnlyXLeftQty(ProductInterface $product): ?float
{
$thresholdQty = (float)$this->scopeConfig->getValue(
Configuration::XML_PATH_STOCK_THRESHOLD_QTY,
ScopeInterface::SCOPE_STORE
);
if ($thresholdQty === 0) {
return null;
}

$stockItem = $this->stockRegistry->getStockItem($product->getId());

$stockCurrentQty = $this->stockRegistry->getStockStatus(
$product->getId(),
$product->getStore()->getWebsiteId()
)->getQty();

$stockLeft = $stockCurrentQty - $stockItem->getMinQty();

$thresholdQty = (float)$this->scopeConfig->getValue(
Configuration::XML_PATH_STOCK_THRESHOLD_QTY,
ScopeInterface::SCOPE_STORE
);

if ($stockCurrentQty > 0 && $stockLeft <= $thresholdQty) {
return $stockLeft;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogInventoryGraphQl\Model\Resolver;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogInventory\Api\Data\StockStatusInterface;
use Magento\CatalogInventory\Api\StockStatusRepositoryInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
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}
*/
class StockStatusProvider implements ResolverInterface
{
/**
* @var ValueFactory
*/
private $valueFactory;

/**
* @var StockStatusRepositoryInterface
*/
private $stockStatusRepository;

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

/**
* {@inheritdoc}
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null): Value
{
if (!array_key_exists('model', $value) || !$value['model'] instanceof ProductInterface) {
$result = function () {
return null;
};

return $this->valueFactory->create($result);
}

/* @var $product ProductInterface */
$product = $value['model'];

$stockStatus = $this->stockStatusRepository->get($product->getId());
$productStockStatus = (int)$stockStatus->getStockStatus();

$result = function () use ($productStockStatus) {
return $productStockStatus === StockStatusInterface::STATUS_IN_STOCK ? 'IN_STOCK' : 'OUT_OF_STOCK';
};

return $this->valueFactory->create($result);
}
}
4 changes: 4 additions & 0 deletions app/code/Magento/CatalogInventoryGraphQl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# CatalogInventoryGraphQl

**CatalogInventoryGraphQl** provides type information for the GraphQl module
to generate inventory stock fields for product information endpoints.
24 changes: 24 additions & 0 deletions app/code/Magento/CatalogInventoryGraphQl/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "magento/module-catalog-inventory-graph-ql",
"description": "N/A",
"type": "magento2-module",
"require": {
"php": "~7.1.3||~7.2.0",
"magento/framework": "*",
"magento/module-store": "*",
"magento/module-catalog": "*",
"magento/module-catalog-inventory": "*"
},
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magento\\CatalogInventoryGraphQl\\": ""
}
}
}
16 changes: 16 additions & 0 deletions app/code/Magento/CatalogInventoryGraphQl/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_CatalogInventoryGraphQl">
<sequence>
<module name="Magento_Store"/>
<module name="Magento_Catalog"/>
<module name="Magento_CatalogInventory"/>
</sequence>
</module>
</config>
12 changes: 12 additions & 0 deletions app/code/Magento/CatalogInventoryGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.

interface ProductInterface {
only_x_left_in_stock: Float @doc(description: "Product stock only x left count") @resolver(class: "Magento\\CatalogInventoryGraphQl\\Model\\Resolver\\OnlyXLeftInStockResolver")
stock_status: ProductStockStatus @doc(description: "Stock status of the product") @resolver(class: "Magento\\CatalogInventoryGraphQl\\Model\\Resolver\\StockStatusProvider")
}

enum ProductStockStatus @doc(description: "This enumeration states whether a product stock status is in stock or out of stock") {
IN_STOCK
OUT_OF_STOCK
}
10 changes: 10 additions & 0 deletions app/code/Magento/CatalogInventoryGraphQl/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_CatalogInventoryGraphQl', __DIR__);
101 changes: 101 additions & 0 deletions app/code/Magento/CmsGraphQl/Model/Resolver/Blocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CmsGraphQl\Model\Resolver;

use Magento\CmsGraphQl\Model\Resolver\DataProvider\Block as BlockDataProvider;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

/**
* CMS blocks field resolver, used for GraphQL request processing
*/
class Blocks implements ResolverInterface
{
/**
* @var BlockDataProvider
*/
private $blockDataProvider;

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

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

/**
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) : Value {

$result = function () use ($args) {
$blockIdentifiers = $this->getBlockIdentifiers($args);
$blocksData = $this->getBlocksData($blockIdentifiers);

$resultData = [
'items' => $blocksData,
];
return $resultData;
};
return $this->valueFactory->create($result);
}

/**
* @param array $args
* @return string[]
* @throws GraphQlInputException
*/
private function getBlockIdentifiers(array $args): array
{
if (!isset($args['identifiers']) || !is_array($args['identifiers']) || count($args['identifiers']) === 0) {
throw new GraphQlInputException(__('"identifiers" of CMS blocks should be specified'));
}

return $args['identifiers'];
}

/**
* @param array $blockIdentifiers
* @return array
* @throws GraphQlNoSuchEntityException
*/
private function getBlocksData(array $blockIdentifiers): array
{
$blocksData = [];
try {
foreach ($blockIdentifiers as $blockIdentifier) {
$blocksData[$blockIdentifier] = $this->blockDataProvider->getData($blockIdentifier);
}
} catch (NoSuchEntityException $e) {
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
}
return $blocksData;
}
}
Loading