From 55387bd5da814d691c7935faaf2c2c37b220aef8 Mon Sep 17 00:00:00 2001 From: TomashKhamlai Date: Tue, 21 Aug 2018 10:47:45 +0300 Subject: [PATCH 01/11] Test coverage for CMS page --- .../Magento/GraphQl/Cms/CmsPageTest.php | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsPageTest.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsPageTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsPageTest.php new file mode 100644 index 0000000000000..fa115a8a49bc6 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsPageTest.php @@ -0,0 +1,136 @@ +get(GetPageByIdentifier::class)->execute('page100', 0); + $pageId = $cmsPage->getPageId(); + $cmsPageData = $cmsPage->getData(); + $query = + <<graphQlQuery($query); + $this->assertEquals($cmsPageData['identifier'], $response['cmsPage']['url_key']); + $this->assertEquals($cmsPageData['title'], $response['cmsPage']['title']); + $this->assertEquals($cmsPageData['content'], $response['cmsPage']['content']); + $this->assertEquals($cmsPageData['content_heading'], $response['cmsPage']['content_heading']); + $this->assertEquals($cmsPageData['page_layout'], $response['cmsPage']['page_layout']); + $this->assertEquals($cmsPageData['meta_title'], $response['cmsPage']['meta_title']); + $this->assertEquals($cmsPageData['meta_description'], $response['cmsPage']['meta_description']); + $this->assertEquals($cmsPageData['meta_keywords'], $response['cmsPage']['meta_keywords']); + } + + /** + * Verify the message when page_id is not specified. + */ + public function testGetCmsPageWithoutId() + { + $query = + <<expectException(\Exception::class); + $this->expectExceptionMessage('Page id should be specified'); + $this->graphQlQuery($query); + } + + /** + * Verify the message when page_id does not exist. + */ + public function testGetCmsPageByNonExistentId() + { + $query = + <<expectException(\Exception::class); + $this->expectExceptionMessage('The CMS page with the "0" ID doesn\'t exist.'); + $this->graphQlQuery($query); + + } + + /** + * Verify the message when CMS Page selected by page_id is disabled + * + * @magentoApiDataFixture Magento/Cms/_files/noroute.php + */ + public function testGetDisabledCmsPageById() + { + $cmsPageId = ObjectManager::getInstance()->get(GetPageByIdentifier::class)->execute('no-route', 0)->getPageId(); + $query = + <<expectException(\Exception::class); + $this->expectExceptionMessage('No such entity.'); + $this->graphQlQuery($query); + } + +} From 5b11b8e02b1ac4d49c68b48c9527714747c539e3 Mon Sep 17 00:00:00 2001 From: TomashKhamlai Date: Tue, 21 Aug 2018 11:59:41 +0300 Subject: [PATCH 02/11] Fix problems reported by testCodeStyle --- .../testsuite/Magento/GraphQl/Cms/CmsPageTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsPageTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsPageTest.php index fa115a8a49bc6..86145fafa62f1 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsPageTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsPageTest.php @@ -11,7 +11,6 @@ use Magento\TestFramework\ObjectManager; use Magento\TestFramework\TestCase\GraphQlAbstract; - class CmsPageTest extends GraphQlAbstract { /** @@ -101,7 +100,6 @@ public function testGetCmsPageByNonExistentId() $this->expectException(\Exception::class); $this->expectExceptionMessage('The CMS page with the "0" ID doesn\'t exist.'); $this->graphQlQuery($query); - } /** @@ -132,5 +130,4 @@ public function testGetDisabledCmsPageById() $this->expectExceptionMessage('No such entity.'); $this->graphQlQuery($query); } - } From 6e78ca6a12330c37c6ea1596dba08614260f985a Mon Sep 17 00:00:00 2001 From: Tomash Khamlai Date: Tue, 21 Aug 2018 19:06:55 +0300 Subject: [PATCH 03/11] Test coverage for CMS block --- .../Magento/GraphQl/Cms/CmsBlockTest.php | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php new file mode 100644 index 0000000000000..9ca1ba381d94c --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php @@ -0,0 +1,138 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + /** + * Verify the fields of CMS Block selected by identifiers + * + * @magentoApiDataFixture Magento/Cms/_files/block.php + */ + public function testGetCmsBlocksByIdentifiers() + { + /** @var StoreManagerInterface $storeManager */ + $storeManager = $this->objectManager->get(StoreManagerInterface::class); + $storeId = (int)$storeManager->getStore()->getId(); + $cmsBlock = $this->objectManager->get(GetBlockByIdentifier::class)->execute("fixture_block", $storeId); + $cmsBlockData = $cmsBlock->getData(); + /** @var FilterEmulate $widgetFilter */ + $widgetFilter = $this->objectManager->get(FilterEmulate::class); + $renderedContent = $widgetFilter->setUseSessionInUrl(false)->filter($cmsBlock->getContent()); + $query = + <<graphQlQuery($query); + $this->assertArrayHasKey('cmsBlocks', $response); + $this->assertArrayHasKey('items', $response['cmsBlocks']); + $this->assertArrayHasKey('content', $response['cmsBlocks']['items'][0]); + $this->assertEquals($cmsBlockData['identifier'], $response['cmsBlocks']['items'][0]['identifier']); + $this->assertEquals($cmsBlockData['title'], $response['cmsBlocks']['items'][0]['title']); + $this->assertEquals($renderedContent, $response['cmsBlocks']['items'][0]['content']); + } + + /** + * Verify the message when CMS Block is disabled + */ + public function testGetDisabledCmsBlockByIdentifiers() + { + /** @var StoreManagerInterface $storeManager */ + $storeManager = $this->objectManager->get(StoreManagerInterface::class); + $storeId = (int)$storeManager->getStore()->getId(); + $cmsBlockId = $this->objectManager->get(GetBlockByIdentifier::class)->execute("fixture_block", $storeId)->getId(); + $this->objectManager->get(Block::class)->load($cmsBlockId)->setIsActive(0)->save(); + $query = + <<expectException(\Exception::class); + $this->expectExceptionMessage('No such entity.'); + $this->graphQlQuery($query); + } + + /** + * Verify the message when identifiers were not specified + */ + public function testGetCmsBlockBypassingIdentifiers() + { + $query = + <<expectException(\Exception::class); + $this->expectExceptionMessage('"identifiers" of CMS blocks should be specified'); + $this->graphQlQuery($query); + } + + /** + * Verify the message when CMS Block with such identifiers does not exist + */ + public function testGetCmsBlockByNonExistentIdentifier() + { + $query = + <<expectException(\Exception::class); + $this->expectExceptionMessage('The CMS block with the "0" ID doesn\'t exist.'); + $this->graphQlQuery($query); + } +} From f8d1c297712265997f0d321667f20e51c0c699f8 Mon Sep 17 00:00:00 2001 From: Tomash Khamlai Date: Wed, 22 Aug 2018 11:27:08 +0300 Subject: [PATCH 04/11] Reformat code --- .../testsuite/Magento/GraphQl/Cms/CmsBlockTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php index 9ca1ba381d94c..b128fa9e75cbf 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php @@ -70,7 +70,8 @@ public function testGetDisabledCmsBlockByIdentifiers() /** @var StoreManagerInterface $storeManager */ $storeManager = $this->objectManager->get(StoreManagerInterface::class); $storeId = (int)$storeManager->getStore()->getId(); - $cmsBlockId = $this->objectManager->get(GetBlockByIdentifier::class)->execute("fixture_block", $storeId)->getId(); + $cmsBlockId = $this->objectManager->get(GetBlockByIdentifier::class)->execute("fixture_block", + $storeId)->getId(); $this->objectManager->get(Block::class)->load($cmsBlockId)->setIsActive(0)->save(); $query = << Date: Wed, 22 Aug 2018 18:41:56 +0300 Subject: [PATCH 05/11] Reformat again --- .../testsuite/Magento/GraphQl/Cms/CmsBlockTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php index b128fa9e75cbf..41bb98d24bfec 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php @@ -70,8 +70,9 @@ public function testGetDisabledCmsBlockByIdentifiers() /** @var StoreManagerInterface $storeManager */ $storeManager = $this->objectManager->get(StoreManagerInterface::class); $storeId = (int)$storeManager->getStore()->getId(); - $cmsBlockId = $this->objectManager->get(GetBlockByIdentifier::class)->execute("fixture_block", - $storeId)->getId(); + $cmsBlockId = $this->objectManager->get(GetBlockByIdentifier::class) + ->execute("fixture_block", $storeId) + ->getId(); $this->objectManager->get(Block::class)->load($cmsBlockId)->setIsActive(0)->save(); $query = << Date: Thu, 23 Aug 2018 16:15:01 +0300 Subject: [PATCH 06/11] Test coverage for added breadcrumbs support #158 --- .../GraphQl/Catalog/BreadcrumbsTest.php | 175 ++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/BreadcrumbsTest.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/BreadcrumbsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/BreadcrumbsTest.php new file mode 100644 index 0000000000000..d0879ae5864ef --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/BreadcrumbsTest.php @@ -0,0 +1,175 @@ +get(CollectionFactory::class)->create(); + $categoryCollection->addAttributeToFilter('name', ['eq' => 'Category 1.1.1']); + $selectedCategoryId = (int)$categoryCollection->getFirstItem()->getId(); + $query = + <<graphQlQuery($query); + $this->assertArrayHasKey('category', $response); + $this->assertArrayHasKey('breadcrumbs', $response['category']); + $this->assertBaseFields($selectedCategoryId, $response); + } + + /** + * Verify the fields of CMS Block selected by identifiers. + * + * @magentoApiDataFixture Magento/Catalog/_files/category_tree.php + * @return void + */ + public function testGetBreadcrumbsForNonExistingCategory(): void + { + $query = + <<graphQlQuery($query); + $this->assertArrayHasKey('category', $response); + $this->assertNull( + $response['category'], + 'Value of "category" field must be NULL if requested category doesn\'t exist' + ); + $this->assertCount( + 1, + $response, + 'There should be only "category" field if requested category doesn\'t exist ' + ); + } + + /** + * Asserts the equality of the response fields to the fields given in assertion map. + * Assert that values of the fields are different from NULL + * + * @param array $actualResponse + * @param array $assertionMap + * @return void + */ + private function assertResponseFields(array $actualResponse, array $assertionMap): void + { + foreach ($assertionMap as $key => $assertionData) { + $expectedValue = isset($assertionData['expected_value']) + ? $assertionData['expected_value'] + : $assertionData; + $responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key; + $this->assertNotNull( + $expectedValue, + "Value of '{$responseField}' field must not be NULL" + ); + $this->assertEquals( + $expectedValue[$key], + $actualResponse[$responseField], + "Value of '{$responseField}' field in response does not match expected value: " + . var_export($expectedValue, true) + ); + } + } + + /** + * Get breadcrumbs for given category. + * + * @param Category $category + * @return array + */ + private function getBreadcrumbs(Category $category): array + { + $breadcrumbs = []; + $rootId = Bootstrap::getObjectManager()->get(StoreManagerInterface::class) + ->getStore() + ->getRootCategoryId(); + foreach ($category->getParentCategories() as $parentCategory) { + if ($parentCategory->getId() !== $rootId) { + $breadcrumbs[] = [ + 'category_id' => $parentCategory->getId(), + 'category_name' => $parentCategory->getName(), + 'category_level' => $parentCategory->getLevel(), + 'category_url_key' => $parentCategory->getUrlKey(), + ]; + } + } + + return $breadcrumbs; + } + + /** + * Asserts base fields + * + * @param int $categoryId + * @param array $actualResponse + * @return void + */ + private function assertBaseFields(int $categoryId, array $actualResponse): void + { + $category = Bootstrap::getObjectManager()->create(Category::class)->load($categoryId); + $assertionMap = [ + [ + 'response_field' => 'category', + 'expected_value' => + [ + [ + 'name' => $category->getName(), + 'breadcrumbs' => $this->getBreadcrumbs($category->getParentCategory()), + ], + + ], + ], + ]; + + /** + * @param array $actualResponse + * @param array $assertionMap ['response_field_name' => 'response_field_value', ...] + * OR [['response_field' => $field, 'expected_value' => $value], ...] + */ + $this->assertResponseFields($actualResponse, $assertionMap); + } +} From 8984c5495579b6901ae2520fdb3f1840984dd8a9 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 11 Sep 2018 17:10:21 +0300 Subject: [PATCH 07/11] GraphQL-152: Allow scalars as resolver return type --- .../Model/Resolver/BundleItemLinks.php | 14 ++- .../Model/Resolver/BundleItems.php | 9 +- .../Model/Resolver/Options/Label.php | 20 ++-- .../Resolver/Product/Fields/DynamicPrice.php | 28 +----- .../Resolver/Product/Fields/DynamicSku.php | 32 +------ .../Resolver/Product/Fields/DynamicWeight.php | 32 +------ .../Resolver/Product/Fields/PriceView.php | 28 ++---- .../Product/Fields/ShipBundleItems.php | 33 ++----- .../Model/Resolver/Categories.php | 8 +- .../Model/Resolver/Category/Breadcrumbs.php | 29 ++---- .../Model/Resolver/Category/Products.php | 33 +++---- .../Model/Resolver/Category/SortFields.php | 20 +--- .../Model/Resolver/CategoryTree.php | 48 ++++------ .../CatalogGraphQl/Model/Resolver/Product.php | 6 +- .../Model/Resolver/Product/CanonicalUrl.php | 33 ++----- .../Model/Resolver/Product/EntityIdToId.php | 27 ++---- .../Resolver/Product/MediaGalleryEntries.php | 30 +----- .../Model/Resolver/Product/NewFromTo.php | 29 +----- .../Model/Resolver/Product/Options.php | 29 +----- .../Model/Resolver/Product/Price.php | 26 +----- .../Model/Resolver/Product/ProductLinks.php | 29 +----- .../Model/Resolver/Product/TierPrices.php | 29 +----- .../Model/Resolver/Product/Websites.php | 12 +-- .../Model/Resolver/Products.php | 20 +--- .../Resolver/Product/CanonicalUrlTest.php | 92 ------------------- .../Resolver/OnlyXLeftInStockResolver.php | 31 ++----- .../Model/Resolver/StockStatusProvider.php | 30 ++---- .../CmsGraphQl/Model/Resolver/Blocks.php | 29 ++---- .../CmsGraphQl/Model/Resolver/Page.php | 24 +---- .../Model/Resolver/ConfigurableVariant.php | 5 +- .../Model/Resolver/Options.php | 7 +- .../Model/Resolver/Variant/Attributes.php | 61 ++++-------- .../Model/Resolver/Customer.php | 21 +---- .../Resolver/Product/DownloadableOptions.php | 26 +----- .../Resolver/CustomAttributeMetadata.php | 18 +--- .../Model/Resolver/GroupedItems.php | 29 ++---- .../Model/Resolver/Cart/CreateEmptyCart.php | 18 +--- .../Store/StoreConfigDataProvider.php | 13 --- .../Model/Resolver/StoreConfigResolver.php | 27 ++---- .../Model/Resolver/UrlRewrite.php | 57 +++++------- .../Model/Resolver/Item.php | 26 +----- .../Model/Resolver/IntegerList.php | 30 +----- .../GraphQl/Query/ResolverInterface.php | 4 +- 43 files changed, 248 insertions(+), 904 deletions(-) delete mode 100644 app/code/Magento/CatalogGraphQl/Test/Unit/Model/Resolver/Product/CanonicalUrlTest.php diff --git a/app/code/Magento/BundleGraphQl/Model/Resolver/BundleItemLinks.php b/app/code/Magento/BundleGraphQl/Model/Resolver/BundleItemLinks.php index f90945d19f948..f55028a7d1a5b 100644 --- a/app/code/Magento/BundleGraphQl/Model/Resolver/BundleItemLinks.php +++ b/app/code/Magento/BundleGraphQl/Model/Resolver/BundleItemLinks.php @@ -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 { @@ -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']); diff --git a/app/code/Magento/BundleGraphQl/Model/Resolver/BundleItems.php b/app/code/Magento/BundleGraphQl/Model/Resolver/BundleItems.php index 9474f825fe5e8..a402ee6d4c299 100644 --- a/app/code/Magento/BundleGraphQl/Model/Resolver/BundleItems.php +++ b/app/code/Magento/BundleGraphQl/Model/Resolver/BundleItems.php @@ -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 { @@ -35,7 +34,7 @@ class BundleItems implements ResolverInterface /** * @var MetadataPool */ - private $metdataPool; + private $metadataPool; /** * @param Collection $bundleOptionCollection @@ -57,9 +56,9 @@ public function __construct( * * {@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]) diff --git a/app/code/Magento/BundleGraphQl/Model/Resolver/Options/Label.php b/app/code/Magento/BundleGraphQl/Model/Resolver/Options/Label.php index a4757108ee5a4..bcddd5d084629 100644 --- a/app/code/Magento/BundleGraphQl/Model/Resolver/Options/Label.php +++ b/app/code/Magento/BundleGraphQl/Model/Resolver/Options/Label.php @@ -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; @@ -19,29 +19,28 @@ */ 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, @@ -49,12 +48,9 @@ public function resolve( 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']); diff --git a/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicPrice.php b/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicPrice.php index e8dc3decc2adf..978e1c455fc0a 100644 --- a/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicPrice.php +++ b/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicPrice.php @@ -5,36 +5,20 @@ */ 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, @@ -42,16 +26,12 @@ public function resolve( 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; } } diff --git a/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicSku.php b/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicSku.php index 37e1557d36df1..73f84c278a634 100644 --- a/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicSku.php +++ b/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicSku.php @@ -5,36 +5,20 @@ */ 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, @@ -42,18 +26,12 @@ public function resolve( 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; } } diff --git a/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicWeight.php b/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicWeight.php index 5f79bba449e54..a4bb8ef64fc98 100644 --- a/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicWeight.php +++ b/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/DynamicWeight.php @@ -5,36 +5,20 @@ */ 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, @@ -42,18 +26,12 @@ public function resolve( 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; } } diff --git a/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/PriceView.php b/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/PriceView.php index ef8e93748c73f..b7351b09d437e 100644 --- a/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/PriceView.php +++ b/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/PriceView.php @@ -5,19 +5,16 @@ */ 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\EnumLookup; -use Magento\Framework\GraphQl\Query\Resolver\Value; -use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; use Magento\Framework\GraphQl\Query\ResolverInterface; /** - * {@inheritdoc} + * @inheritdoc */ class PriceView implements ResolverInterface { @@ -26,23 +23,16 @@ class PriceView implements ResolverInterface */ private $enumLookup; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @param EnumLookup $enumLookup - * @param ValueFactory $valueFactory */ - public function __construct(EnumLookup $enumLookup, ValueFactory $valueFactory) + public function __construct(EnumLookup $enumLookup) { $this->enumLookup = $enumLookup; - $this->valueFactory = $valueFactory; } /** - * {@inheritdoc} + * @inheritdoc */ public function resolve( Field $field, @@ -50,19 +40,13 @@ public function resolve( 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['price_view']) ? $this->enumLookup->getEnumValueFromField('PriceViewEnum', $value['price_view']) : null; } - return $this->valueFactory->create( - function () use ($result) { - return $result; - } - ); + return $result; } } diff --git a/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/ShipBundleItems.php b/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/ShipBundleItems.php index e2bd12a84e2b4..6babf6520e10e 100644 --- a/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/ShipBundleItems.php +++ b/app/code/Magento/BundleGraphQl/Model/Resolver/Product/Fields/ShipBundleItems.php @@ -5,19 +5,16 @@ */ 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\EnumLookup; -use Magento\Framework\GraphQl\Query\Resolver\Value; -use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; use Magento\Framework\GraphQl\Query\ResolverInterface; /** - * {@inheritdoc} + * @inheritdoc */ class ShipBundleItems implements ResolverInterface { @@ -26,23 +23,16 @@ class ShipBundleItems implements ResolverInterface */ private $enumLookup; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @param EnumLookup $enumLookup - * @param ValueFactory $valueFactory */ - public function __construct(EnumLookup $enumLookup, ValueFactory $valueFactory) + public function __construct(EnumLookup $enumLookup) { $this->enumLookup = $enumLookup; - $this->valueFactory = $valueFactory; } /** - * {@inheritdoc} + * @inheritdoc */ public function resolve( Field $field, @@ -50,19 +40,10 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { - $result = function () { - return null; - }; - if ($value['type_id'] === Bundle::TYPE_CODE) { - $result = isset($value['shipment_type']) - ? $this->enumLookup->getEnumValueFromField('ShipBundleItemsEnum', $value['shipment_type']) : null; - } + ) { + $result = isset($value['shipment_type']) && $value['type_id'] === Bundle::TYPE_CODE + ? $this->enumLookup->getEnumValueFromField('ShipBundleItemsEnum', $value['shipment_type']) : null; - return $this->valueFactory->create( - function () use ($result) { - return $result; - } - ); + return $result; } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Categories.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Categories.php index 378e7cb4c3673..5ab9e0ad273e6 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Categories.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Categories.php @@ -7,6 +7,7 @@ namespace Magento\CatalogGraphQl\Model\Resolver; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Catalog\Api\Data\CategoryInterface; use Magento\Catalog\Model\ResourceModel\Category\Collection; @@ -15,7 +16,6 @@ use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CustomAttributesFlattener; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\ResolverInterface; -use Magento\Framework\GraphQl\Query\Resolver\Value; use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; use Magento\Framework\Reflection\DataObjectProcessor; @@ -82,8 +82,12 @@ public function __construct( * {@inheritdoc} * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - 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['model'])) { + throw new GraphQlInputException(__('"model" value should be specified')); + } + /** @var \Magento\Catalog\Model\Product $product */ $product = $value['model']; $categoryIds = $product->getCategoryIds(); diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/Breadcrumbs.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/Breadcrumbs.php index d49c7f5e5674d..9e966a060e5c6 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/Breadcrumbs.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/Breadcrumbs.php @@ -7,12 +7,11 @@ namespace Magento\CatalogGraphQl\Model\Resolver\Category; -use \Magento\CatalogGraphQl\Model\Resolver\Category\DataProvider\Breadcrumbs as BreadcrumbsDataProvider; +use Magento\CatalogGraphQl\Model\Resolver\Category\DataProvider\Breadcrumbs as BreadcrumbsDataProvider; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\ResolverInterface; -use Magento\Framework\GraphQl\Query\Resolver\Value; -use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; /** * Retrieves breadcrumbs @@ -24,39 +23,25 @@ class Breadcrumbs implements ResolverInterface */ private $breadcrumbsDataProvider; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @param BreadcrumbsDataProvider $breadcrumbsDataProvider - * @param ValueFactory $valueFactory */ public function __construct( - BreadcrumbsDataProvider $breadcrumbsDataProvider, - ValueFactory $valueFactory + BreadcrumbsDataProvider $breadcrumbsDataProvider ) { $this->breadcrumbsDataProvider = $breadcrumbsDataProvider; - $this->valueFactory = $valueFactory; } /** * @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['path'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"path" value should be specified')); } - $result = function () use ($value) { - $breadcrumbsData = $this->breadcrumbsDataProvider->getData($value['path']); - return count($breadcrumbsData) ? $breadcrumbsData : null; - }; - return $this->valueFactory->create($result); + $breadcrumbsData = $this->breadcrumbsDataProvider->getData($value['path']); + return count($breadcrumbsData) ? $breadcrumbsData : null; } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/Products.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/Products.php index 406b4173e68e1..557c7e08ff432 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/Products.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/Products.php @@ -9,8 +9,6 @@ use Magento\Catalog\Api\ProductRepositoryInterface; 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\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder; @@ -22,38 +20,38 @@ */ class Products implements ResolverInterface { - /** @var \Magento\Catalog\Api\ProductRepositoryInterface */ + /** + * @var \Magento\Catalog\Api\ProductRepositoryInterface + */ private $productRepository; - /** @var Builder */ + /** + * @var Builder + */ private $searchCriteriaBuilder; - /** @var Filter */ + /** + * @var Filter + */ private $filterQuery; - /** @var ValueFactory */ - private $valueFactory; - /** * @param ProductRepositoryInterface $productRepository * @param Builder $searchCriteriaBuilder * @param Filter $filterQuery - * @param ValueFactory $valueFactory */ public function __construct( ProductRepositoryInterface $productRepository, Builder $searchCriteriaBuilder, - Filter $filterQuery, - ValueFactory $valueFactory + Filter $filterQuery ) { $this->productRepository = $productRepository; $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->filterQuery = $filterQuery; - $this->valueFactory = $valueFactory; } /** - * {@inheritdoc} + * @inheritdoc */ public function resolve( Field $field, @@ -61,7 +59,7 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { $args['filter'] = [ 'category_id' => [ 'eq' => $value['id'] @@ -97,11 +95,6 @@ public function resolve( 'current_page' => $currentPage ] ]; - - $result = function () use ($data) { - return $data; - }; - - return $this->valueFactory->create($result); + return $data; } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/SortFields.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/SortFields.php index ca68b29910118..cb5553bb03701 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/SortFields.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/SortFields.php @@ -9,8 +9,6 @@ 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; /** @@ -18,11 +16,6 @@ */ class SortFields implements ResolverInterface { - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @var \Magento\Catalog\Model\Config */ @@ -39,27 +32,24 @@ class SortFields implements ResolverInterface private $sortbyAttributeSource; /** - * @param ValueFactory $valueFactory * @param \Magento\Catalog\Model\Config $catalogConfig * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @oaram \Magento\Catalog\Model\Category\Attribute\Source\Sortby $sortbyAttributeSource */ public function __construct( - ValueFactory $valueFactory, \Magento\Catalog\Model\Config $catalogConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Category\Attribute\Source\Sortby $sortbyAttributeSource ) { - $this->valueFactory = $valueFactory; $this->catalogConfig = $catalogConfig; $this->storeManager = $storeManager; $this->sortbyAttributeSource = $sortbyAttributeSource; } /** - * {@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) { $sortFieldsOptions = $this->sortbyAttributeSource->getAllOptions(); array_walk( @@ -73,10 +63,6 @@ function (&$option) { 'options' => $sortFieldsOptions, ]; - $result = function () use ($data) { - return $data; - }; - - return $this->valueFactory->create($result); + return $data; } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php index f631e5ff61d2e..6d9f5e33dd55b 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php @@ -11,8 +11,6 @@ use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Query\ResolverInterface; -use Magento\Framework\GraphQl\Query\Resolver\Value; -use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; /** * Category tree field resolver, used for GraphQL request processing. @@ -25,60 +23,48 @@ class CategoryTree implements ResolverInterface const CATEGORY_INTERFACE = 'CategoryInterface'; /** - * @var Products\DataProvider\CategoryTree + * @var \Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree */ private $categoryTree; /** - * @var ValueFactory - */ - private $valueFactory; - - /** - * @param Products\DataProvider\CategoryTree $categoryTree - * @param ValueFactory $valueFactory + * @param \Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree $categoryTree */ public function __construct( - \Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree $categoryTree, - ValueFactory $valueFactory + \Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree $categoryTree ) { $this->categoryTree = $categoryTree; - $this->valueFactory = $valueFactory; } /** - * Assert that filters from search criteria are valid and retrieve root category id - * * @param array $args * @return int * @throws GraphQlInputException */ - private function assertFiltersAreValidAndGetCategoryRootIds(array $args) : int + private function getCategoryId(array $args) : int { if (!isset($args['id'])) { throw new GraphQlInputException(__('"id for category should be specified')); } - return (int) $args['id']; + return (int)$args['id']; } /** - * {@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) { - return $this->valueFactory->create(function () use ($value, $args, $field, $info) { - if (isset($value[$field->getName()])) { - return $value[$field->getName()]; - } + if (isset($value[$field->getName()])) { + return $value[$field->getName()]; + } - $rootCategoryId = $this->assertFiltersAreValidAndGetCategoryRootIds($args); - $categoriesTree = $this->categoryTree->getTree($info, $rootCategoryId); - if (!empty($categoriesTree)) { - return current($categoriesTree); - } else { - return null; - } - }); + $rootCategoryId = $this->getCategoryId($args); + $categoriesTree = $this->categoryTree->getTree($info, $rootCategoryId); + if (!empty($categoriesTree)) { + return current($categoriesTree); + } else { + return null; + } } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product.php index 8bf3335bbb9d8..40aa54fd93873 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product.php @@ -17,7 +17,7 @@ use Magento\Framework\GraphQl\Query\ResolverInterface; /** - * {@inheritdoc} + * @inheritdoc */ class Product implements ResolverInterface { @@ -52,9 +52,9 @@ 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['sku'])) { throw new GraphQlInputException(__('No child sku found for product link.')); diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CanonicalUrl.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CanonicalUrl.php index d2675848c2d2a..0f1a7d8ee9dab 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CanonicalUrl.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CanonicalUrl.php @@ -9,8 +9,7 @@ use Magento\Catalog\Model\Product; 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\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; @@ -20,21 +19,7 @@ class CanonicalUrl implements ResolverInterface { /** - * @var ValueFactory - */ - private $valueFactory; - - /** - * @param ValueFactory $valueFactory - */ - public function __construct( - ValueFactory $valueFactory - ) { - $this->valueFactory = $valueFactory; - } - - /** - * {@inheritdoc} + * @inheritdoc */ public function resolve( Field $field, @@ -42,21 +27,15 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { if (!isset($value['model'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } /* @var $product Product */ $product = $value['model']; $url = $product->getUrlModel()->getUrl($product, ['_ignore_category' => true]); - $result = function () use ($url) { - return $url; - }; - - return $this->valueFactory->create($result); + + return $url; } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/EntityIdToId.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/EntityIdToId.php index 4c101f68eb4da..a09510be8bc7d 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/EntityIdToId.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/EntityIdToId.php @@ -7,13 +7,12 @@ namespace Magento\CatalogGraphQl\Model\Resolver\Product; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Model\Product; 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; /** @@ -28,23 +27,16 @@ class EntityIdToId implements ResolverInterface */ private $metadataPool; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @param MetadataPool $metadataPool - * @param ValueFactory $valueFactory */ - public function __construct(MetadataPool $metadataPool, ValueFactory $valueFactory) + public function __construct(MetadataPool $metadataPool) { $this->metadataPool = $metadataPool; - $this->valueFactory = $valueFactory; } /** - * {@inheritDoc} + * @inheritdoc */ public function resolve( Field $field, @@ -52,12 +44,9 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { if (!isset($value['model'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } /** @var Product $product */ @@ -67,10 +56,6 @@ public function resolve( $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField() ); - $result = function () use ($productId) { - return $productId; - }; - - return $this->valueFactory->create($result); + return $productId; } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/MediaGalleryEntries.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/MediaGalleryEntries.php index ac028eef1fb1d..a54cb62c16527 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/MediaGalleryEntries.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/MediaGalleryEntries.php @@ -7,11 +7,10 @@ namespace Magento\CatalogGraphQl\Model\Resolver\Product; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Catalog\Model\Product; 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; /** @@ -19,19 +18,6 @@ */ class MediaGalleryEntries implements ResolverInterface { - /** - * @var ValueFactory - */ - private $valueFactory; - - /** - * @param ValueFactory $valueFactory - */ - public function __construct(ValueFactory $valueFactory) - { - $this->valueFactory = $valueFactory; - } - /** * Format product's media gallery entry data to conform to GraphQL schema * @@ -43,12 +29,9 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { if (!isset($value['model'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } /** @var Product $product */ @@ -64,11 +47,6 @@ public function resolve( } } } - - $result = function () use ($mediaGalleryEntries) { - return $mediaGalleryEntries; - }; - - return $this->valueFactory->create($result); + return $mediaGalleryEntries; } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/NewFromTo.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/NewFromTo.php index 34fb58b97b156..2fa47f86ecb9d 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/NewFromTo.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/NewFromTo.php @@ -7,11 +7,10 @@ namespace Magento\CatalogGraphQl\Model\Resolver\Product; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Catalog\Model\Product; 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; /** @@ -19,19 +18,6 @@ */ class NewFromTo implements ResolverInterface { - /** - * @var ValueFactory - */ - private $valueFactory; - - /** - * @param ValueFactory $valueFactory - */ - public function __construct(ValueFactory $valueFactory) - { - $this->valueFactory = $valueFactory; - } - /** * Transfer data from legacy news_from_date and news_to_date to new names corespondent fields * @@ -43,12 +29,9 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { if (!isset($value['model'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } /** @var Product $product */ @@ -60,10 +43,6 @@ public function resolve( $data = $product->getData($attributeName); } - $result = function () use ($data) { - return $data; - }; - - return $this->valueFactory->create($result); + return $data; } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Options.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Options.php index 8e06877452ff4..7c7e4ef117a50 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Options.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Options.php @@ -7,12 +7,11 @@ namespace Magento\CatalogGraphQl\Model\Resolver\Product; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product\Option; 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; /** @@ -20,19 +19,6 @@ */ class Options implements ResolverInterface { - /** - * @var ValueFactory - */ - private $valueFactory; - - /** - * @param ValueFactory $valueFactory - */ - public function __construct(ValueFactory $valueFactory) - { - $this->valueFactory = $valueFactory; - } - /** * Format product's option data to conform to GraphQL schema * @@ -44,12 +30,9 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { if (!isset($value['model'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } /** @var Product $product */ @@ -80,10 +63,6 @@ public function resolve( } } - $result = function () use ($options) { - return $options; - }; - - return $this->valueFactory->create($result); + return $options; } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Price.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Price.php index 29b693abc2661..6f4f8553a324a 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Price.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Price.php @@ -7,13 +7,12 @@ namespace Magento\CatalogGraphQl\Model\Resolver\Product; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Catalog\Model\Product; use Magento\Catalog\Pricing\Price\FinalPrice; use Magento\Catalog\Pricing\Price\RegularPrice; 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\Framework\Pricing\Adjustment\AdjustmentInterface; use Magento\Framework\Pricing\Amount\AmountInterface; @@ -35,24 +34,16 @@ class Price implements ResolverInterface */ private $priceInfoFactory; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @param StoreManagerInterface $storeManager * @param PriceInfoFactory $priceInfoFactory - * @param ValueFactory $valueFactory */ public function __construct( StoreManagerInterface $storeManager, - PriceInfoFactory $priceInfoFactory, - ValueFactory $valueFactory + PriceInfoFactory $priceInfoFactory ) { $this->storeManager = $storeManager; $this->priceInfoFactory = $priceInfoFactory; - $this->valueFactory = $valueFactory; } /** @@ -66,12 +57,9 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { if (!isset($value['model'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } /** @var Product $product */ @@ -90,11 +78,7 @@ public function resolve( 'maximalPrice' => $this->createAdjustmentsArray($priceInfo->getAdjustments(), $maximalPriceAmount) ]; - $result = function () use ($prices) { - return $prices; - }; - - return $this->valueFactory->create($result); + return $prices; } /** diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductLinks.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductLinks.php index 181371f16d3ad..4d5622bd5c6d0 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductLinks.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductLinks.php @@ -7,12 +7,11 @@ namespace Magento\CatalogGraphQl\Model\Resolver\Product; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Catalog\Model\Product; use Magento\Catalog\Model\ProductLink\Link; 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; /** @@ -27,19 +26,6 @@ class ProductLinks implements ResolverInterface */ private $linkTypes = ['related', 'upsell', 'crosssell']; - /** - * @var ValueFactory - */ - private $valueFactory; - - /** - * @param ValueFactory $valueFactory - */ - public function __construct(ValueFactory $valueFactory) - { - $this->valueFactory = $valueFactory; - } - /** * Format product links data to conform to GraphQL schema * @@ -51,12 +37,9 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { if (!isset($value['model'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } /** @var Product $product */ @@ -73,10 +56,6 @@ public function resolve( } } - $result = function () use ($links) { - return $links; - }; - - return $this->valueFactory->create($result); + return $links; } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/TierPrices.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/TierPrices.php index 0b7811d4f743e..63599a88c79a0 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/TierPrices.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/TierPrices.php @@ -7,12 +7,11 @@ namespace Magento\CatalogGraphQl\Model\Resolver\Product; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product\TierPrice; 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; /** @@ -22,19 +21,6 @@ */ class TierPrices implements ResolverInterface { - /** - * @var ValueFactory - */ - private $valueFactory; - - /** - * @param ValueFactory $valueFactory - */ - public function __construct(ValueFactory $valueFactory) - { - $this->valueFactory = $valueFactory; - } - /** * Format product's tier price data to conform to GraphQL schema * @@ -46,12 +32,9 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { if (!isset($value['model'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } /** @var Product $product */ @@ -66,10 +49,6 @@ public function resolve( } } - $result = function () use ($tierPrices) { - return $tierPrices; - }; - - return $this->valueFactory->create($result); + return $tierPrices; } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Websites.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Websites.php index 867f1fa0d0b0d..9fe64a16935c7 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Websites.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Websites.php @@ -7,10 +7,9 @@ namespace Magento\CatalogGraphQl\Model\Resolver\Product; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; -use Magento\Catalog\Model\Product; 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\CatalogGraphQl\Model\Resolver\Product\Websites\Collection; @@ -43,15 +42,12 @@ 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['entity_id'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } $this->productWebsitesCollection->addIdFilters((int)$value['entity_id']); $result = function () use ($value) { diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products.php index cc791ce780c14..0f618058e06df 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products.php @@ -14,8 +14,6 @@ use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder; use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\SearchFilter; -use Magento\Framework\GraphQl\Query\Resolver\Value; -use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Catalog\Model\Layer\Resolver; @@ -44,11 +42,6 @@ class Products implements ResolverInterface */ private $searchFilter; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @var Layer\DataProvider\Filters */ @@ -58,26 +51,23 @@ class Products implements ResolverInterface * @param Builder $searchCriteriaBuilder * @param Search $searchQuery * @param Filter $filterQuery - * @param ValueFactory $valueFactory */ public function __construct( Builder $searchCriteriaBuilder, Search $searchQuery, Filter $filterQuery, SearchFilter $searchFilter, - ValueFactory $valueFactory, \Magento\CatalogGraphQl\Model\Resolver\Layer\DataProvider\Filters $filtersDataProvider ) { $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->searchQuery = $searchQuery; $this->filterQuery = $filterQuery; $this->searchFilter = $searchFilter; - $this->valueFactory = $valueFactory; $this->filtersDataProvider = $filtersDataProvider; } /** - * {@inheritdoc} + * @inheritdoc */ public function resolve( Field $field, @@ -85,7 +75,7 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ) : Value { + ) { $searchCriteria = $this->searchCriteriaBuilder->build($field->getName(), $args); $searchCriteria->setCurrentPage($args['currentPage']); $searchCriteria->setPageSize($args['pageSize']); @@ -128,10 +118,6 @@ public function resolve( 'filters' => $this->filtersDataProvider->getData($layerType) ]; - $result = function () use ($data) { - return $data; - }; - - return $this->valueFactory->create($result); + return $data; } } diff --git a/app/code/Magento/CatalogGraphQl/Test/Unit/Model/Resolver/Product/CanonicalUrlTest.php b/app/code/Magento/CatalogGraphQl/Test/Unit/Model/Resolver/Product/CanonicalUrlTest.php deleted file mode 100644 index ae01c67eb5224..0000000000000 --- a/app/code/Magento/CatalogGraphQl/Test/Unit/Model/Resolver/Product/CanonicalUrlTest.php +++ /dev/null @@ -1,92 +0,0 @@ -getMockBuilder(\Magento\Framework\GraphQl\Config\Element\Field::class) - ->disableOriginalConstructor() - ->getMock(); - $mockInfo = $this->getMockBuilder(\Magento\Framework\GraphQl\Schema\Type\ResolveInfo::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->mockValueFactory->method('create')->with( - $this->callback( - function ($param) { - return $param() === null; - } - ) - ); - - $this->subject->resolve($mockField, '', $mockInfo, [], []); - } - - protected function setUp() - { - parent::setUp(); - $this->objectManager = new ObjectManager($this); - $this->mockStoreManager = $this->getMockBuilder(StoreManagerInterface::class)->getMock(); - $this->mockValueFactory = $this->getMockBuilder(ValueFactory::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->mockValueFactory->method('create')->willReturn( - $this->objectManager->getObject( - Value::class, - ['callback' => function () { - return ''; - }] - ) - ); - - $mockProductUrlPathGenerator = $this->getMockBuilder(ProductUrlPathGenerator::class) - ->disableOriginalConstructor() - ->getMock(); - $mockProductUrlPathGenerator->method('getUrlPathWithSuffix')->willReturn('product_url.html'); - - $this->subject = $this->objectManager->getObject( - CanonicalUrl::class, - [ - 'valueFactory' => $this->mockValueFactory, - 'storeManager' => $this->mockStoreManager, - 'productUrlPathGenerator' => $mockProductUrlPathGenerator - ] - ); - } -} diff --git a/app/code/Magento/CatalogInventoryGraphQl/Model/Resolver/OnlyXLeftInStockResolver.php b/app/code/Magento/CatalogInventoryGraphQl/Model/Resolver/OnlyXLeftInStockResolver.php index e6966b7663b3d..169456f7d4bbd 100644 --- a/app/code/Magento/CatalogInventoryGraphQl/Model/Resolver/OnlyXLeftInStockResolver.php +++ b/app/code/Magento/CatalogInventoryGraphQl/Model/Resolver/OnlyXLeftInStockResolver.php @@ -11,23 +11,17 @@ use Magento\CatalogInventory\Api\StockRegistryInterface; use Magento\CatalogInventory\Model\Configuration; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; 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} + * @inheritdoc */ class OnlyXLeftInStockResolver implements ResolverInterface { - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @var ScopeConfigInterface */ @@ -39,42 +33,31 @@ class OnlyXLeftInStockResolver implements ResolverInterface 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} + * @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 (!array_key_exists('model', $value) || !$value['model'] instanceof ProductInterface) { - $result = function () { - return null; - }; - - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } /* @var $product ProductInterface */ $product = $value['model']; $onlyXLeftQty = $this->getOnlyXLeftQty($product); - $result = function () use ($onlyXLeftQty) { - return $onlyXLeftQty; - }; - - return $this->valueFactory->create($result); + return $onlyXLeftQty; } /** @@ -109,7 +92,7 @@ private function getOnlyXLeftQty(ProductInterface $product): ?float ); if ($stockCurrentQty > 0 && $stockLeft <= $thresholdQty) { - return $stockLeft; + return (float)$stockLeft; } return null; diff --git a/app/code/Magento/CatalogInventoryGraphQl/Model/Resolver/StockStatusProvider.php b/app/code/Magento/CatalogInventoryGraphQl/Model/Resolver/StockStatusProvider.php index 936db3bc76a91..2f3d520c2cb8f 100644 --- a/app/code/Magento/CatalogInventoryGraphQl/Model/Resolver/StockStatusProvider.php +++ b/app/code/Magento/CatalogInventoryGraphQl/Model/Resolver/StockStatusProvider.php @@ -10,48 +10,36 @@ use Magento\Catalog\Api\Data\ProductInterface; use Magento\CatalogInventory\Api\Data\StockStatusInterface; use Magento\CatalogInventory\Api\StockStatusRepositoryInterface; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; 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} + * @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) + public function __construct(StockStatusRepositoryInterface $stockStatusRepository) { - $this->valueFactory = $valueFactory; $this->stockStatusRepository = $stockStatusRepository; } /** - * {@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 (!array_key_exists('model', $value) || !$value['model'] instanceof ProductInterface) { - $result = function () { - return null; - }; - - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } /* @var $product ProductInterface */ @@ -60,10 +48,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value $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); + return $productStockStatus === StockStatusInterface::STATUS_IN_STOCK ? 'IN_STOCK' : 'OUT_OF_STOCK'; } } diff --git a/app/code/Magento/CmsGraphQl/Model/Resolver/Blocks.php b/app/code/Magento/CmsGraphQl/Model/Resolver/Blocks.php index ec387013ecfe6..962127e16f716 100644 --- a/app/code/Magento/CmsGraphQl/Model/Resolver/Blocks.php +++ b/app/code/Magento/CmsGraphQl/Model/Resolver/Blocks.php @@ -12,8 +12,6 @@ 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; @@ -27,21 +25,13 @@ class Blocks implements ResolverInterface */ private $blockDataProvider; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @param BlockDataProvider $blockDataProvider - * @param ValueFactory $valueFactory */ public function __construct( - BlockDataProvider $blockDataProvider, - ValueFactory $valueFactory + BlockDataProvider $blockDataProvider ) { $this->blockDataProvider = $blockDataProvider; - $this->valueFactory = $valueFactory; } /** @@ -53,18 +43,15 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ) : Value { + ) { - $result = function () use ($args) { - $blockIdentifiers = $this->getBlockIdentifiers($args); - $blocksData = $this->getBlocksData($blockIdentifiers); + $blockIdentifiers = $this->getBlockIdentifiers($args); + $blocksData = $this->getBlocksData($blockIdentifiers); - $resultData = [ - 'items' => $blocksData, - ]; - return $resultData; - }; - return $this->valueFactory->create($result); + $resultData = [ + 'items' => $blocksData, + ]; + return $resultData; } /** diff --git a/app/code/Magento/CmsGraphQl/Model/Resolver/Page.php b/app/code/Magento/CmsGraphQl/Model/Resolver/Page.php index 4c96ae26f6b7d..1077ab81551c2 100644 --- a/app/code/Magento/CmsGraphQl/Model/Resolver/Page.php +++ b/app/code/Magento/CmsGraphQl/Model/Resolver/Page.php @@ -12,8 +12,6 @@ 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; @@ -27,21 +25,13 @@ class Page implements ResolverInterface */ private $pageDataProvider; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @param PageDataProvider $pageDataProvider - * @param ValueFactory $valueFactory */ public function __construct( - PageDataProvider $pageDataProvider, - ValueFactory $valueFactory + PageDataProvider $pageDataProvider ) { $this->pageDataProvider = $pageDataProvider; - $this->valueFactory = $valueFactory; } /** @@ -53,15 +43,11 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ) : Value { - - $result = function () use ($args) { - $pageId = $this->getPageId($args); - $pageData = $this->getPageData($pageId); + ) { + $pageId = $this->getPageId($args); + $pageData = $this->getPageData($pageId); - return $pageData; - }; - return $this->valueFactory->create($result); + return $pageData; } /** diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php index e63c75d500327..a6e39f693b0e5 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php @@ -16,12 +16,11 @@ use Magento\ConfigurableProductGraphQl\Model\Variant\Collection; 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 ConfigurableVariant implements ResolverInterface { @@ -76,7 +75,7 @@ public function __construct( * * {@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->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); if ($value['type_id'] !== Type::TYPE_CODE || !isset($value[$linkField])) { diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Options.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Options.php index 53912f7029e55..aa7ed6f55254c 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Options.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Options.php @@ -13,12 +13,11 @@ use Magento\ConfigurableProductGraphQl\Model\Options\Collection as OptionCollection; 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 Options implements ResolverInterface { @@ -55,9 +54,9 @@ public function __construct( /** * Fetch and format configurable variants. * - * {@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) { $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); if ($value['type_id'] !== Type::TYPE_CODE || !isset($value[$linkField])) { diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php index 9c275de3f0962..658e898f09f81 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php @@ -9,8 +9,6 @@ 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; /** @@ -18,19 +16,6 @@ */ class Attributes implements ResolverInterface { - /** - * @var ValueFactory - */ - private $valueFactory; - - /** - * @param ValueFactory $valueFactory - */ - public function __construct(ValueFactory $valueFactory) - { - $this->valueFactory = $valueFactory; - } - /** * Format product's option data to conform to GraphQL schema * @@ -42,38 +27,30 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { if (!isset($value['options']) || !isset($value['product'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + return null; } - $result = function () use ($value) { - $data = []; - foreach ($value['options'] as $option) { - $code = $option['attribute_code']; - if (!isset($value['product'][$code])) { - continue; - } + $data = []; + foreach ($value['options'] as $option) { + $code = $option['attribute_code']; + if (!isset($value['product'][$code])) { + continue; + } - foreach ($option['values'] as $optionValue) { - if ($optionValue['value_index'] != $value['product'][$code]) { - continue; - } - $data[] = [ - 'label' => $optionValue['label'], - 'code' => $code, - 'use_default_value' => $optionValue['use_default_value'], - 'value_index' => $optionValue['value_index'] - ]; + foreach ($option['values'] as $optionValue) { + if ($optionValue['value_index'] != $value['product'][$code]) { + continue; } + $data[] = [ + 'label' => $optionValue['label'], + 'code' => $code, + 'use_default_value' => $optionValue['use_default_value'], + 'value_index' => $optionValue['value_index'] + ]; } - - return $data; - }; - - return $this->valueFactory->create($result); + } + return $data; } } diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer.php index 1cf85381d3467..98941af3b73d2 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer.php @@ -15,8 +15,6 @@ use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; -use Magento\Framework\GraphQl\Query\Resolver\Value; -use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; use Magento\Framework\GraphQl\Query\ResolverInterface; /** @@ -29,25 +27,17 @@ class Customer implements ResolverInterface */ private $customerResolver; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @param CustomerDataProvider $customerResolver - * @param ValueFactory $valueFactory */ public function __construct( - CustomerDataProvider $customerResolver, - ValueFactory $valueFactory + CustomerDataProvider $customerResolver ) { $this->customerResolver = $customerResolver; - $this->valueFactory = $valueFactory; } /** - * {@inheritdoc} + * @inheritdoc */ public function resolve( Field $field, @@ -55,7 +45,7 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ) : Value { + ) { /** @var ContextInterface $context */ if ((!$context->getUserId()) || $context->getUserType() == UserContextInterface::USER_TYPE_GUEST) { throw new GraphQlAuthorizationException( @@ -68,10 +58,7 @@ public function resolve( try { $data = $this->customerResolver->getCustomerById($context->getUserId()); - $result = function () use ($data) { - return !empty($data) ? $data : []; - }; - return $this->valueFactory->create($result); + return !empty($data) ? $data : []; } catch (NoSuchEntityException $exception) { throw new GraphQlNoSuchEntityException(__('Customer id %1 does not exist.', [$context->getUserId()])); } diff --git a/app/code/Magento/DownloadableGraphQl/Model/Resolver/Product/DownloadableOptions.php b/app/code/Magento/DownloadableGraphQl/Model/Resolver/Product/DownloadableOptions.php index cda853a16afa2..5141361fecc0e 100644 --- a/app/code/Magento/DownloadableGraphQl/Model/Resolver/Product/DownloadableOptions.php +++ b/app/code/Magento/DownloadableGraphQl/Model/Resolver/Product/DownloadableOptions.php @@ -7,6 +7,7 @@ namespace Magento\DownloadableGraphQl\Model\Resolver\Product; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Catalog\Model\Product; use Magento\Downloadable\Helper\Data as DownloadableHelper; @@ -16,8 +17,6 @@ use Magento\Framework\Data\Collection; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\EnumLookup; -use Magento\Framework\GraphQl\Query\Resolver\Value; -use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; use Magento\Framework\GraphQl\Query\ResolverInterface; /** @@ -47,30 +46,22 @@ class DownloadableOptions implements ResolverInterface */ private $linkCollection; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @param EnumLookup $enumLookup * @param DownloadableHelper $downloadableHelper * @param SampleCollection $sampleCollection * @param LinkCollection $linkCollection - * @param ValueFactory $valueFactory */ public function __construct( EnumLookup $enumLookup, DownloadableHelper $downloadableHelper, SampleCollection $sampleCollection, - LinkCollection $linkCollection, - ValueFactory $valueFactory + LinkCollection $linkCollection ) { $this->enumLookup = $enumLookup; $this->downloadableHelper = $downloadableHelper; $this->sampleCollection = $sampleCollection; $this->linkCollection = $linkCollection; - $this->valueFactory = $valueFactory; } /** @@ -84,12 +75,9 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { if (!isset($value['model'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } /** @var Product $product */ @@ -113,11 +101,7 @@ public function resolve( } } - $result = function () use ($data) { - return $data; - }; - - return $this->valueFactory->create($result); + return $data; } /** diff --git a/app/code/Magento/EavGraphQl/Model/Resolver/CustomAttributeMetadata.php b/app/code/Magento/EavGraphQl/Model/Resolver/CustomAttributeMetadata.php index 89d2ab9f9d051..62e3f01836619 100644 --- a/app/code/Magento/EavGraphQl/Model/Resolver/CustomAttributeMetadata.php +++ b/app/code/Magento/EavGraphQl/Model/Resolver/CustomAttributeMetadata.php @@ -14,8 +14,6 @@ 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; /** @@ -28,20 +26,16 @@ class CustomAttributeMetadata implements ResolverInterface */ private $type; - private $valueFactory; - /** * @param Type $type - * @param ValueFactory $valueFactory */ - public function __construct(Type $type, ValueFactory $valueFactory) + public function __construct(Type $type) { $this->type = $type; - $this->valueFactory = $valueFactory; } /** - * {@inheritDoc} + * @inheritdoc */ public function resolve( Field $field, @@ -49,7 +43,7 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ) : Value { + ) { $attributes['items'] = null; $attributeInputs = $args['attributes']; foreach ($attributeInputs as $attribute) { @@ -88,11 +82,7 @@ public function resolve( ]; } - $result = function () use ($attributes) { - return $attributes; - }; - - return $this->valueFactory->create($result); + return $attributes; } /** diff --git a/app/code/Magento/GroupedProductGraphQl/Model/Resolver/GroupedItems.php b/app/code/Magento/GroupedProductGraphQl/Model/Resolver/GroupedItems.php index fafbbcf436e64..fee4063affef1 100644 --- a/app/code/Magento/GroupedProductGraphQl/Model/Resolver/GroupedItems.php +++ b/app/code/Magento/GroupedProductGraphQl/Model/Resolver/GroupedItems.php @@ -7,43 +7,34 @@ namespace Magento\GroupedProductGraphQl\Model\Resolver; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Deferred\Product; 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\GroupedProduct\Model\Product\Initialization\Helper\ProductLinks\Plugin\Grouped; /** - * {@inheritdoc} + * @inheritdoc */ class GroupedItems implements ResolverInterface { - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @var Product */ private $productResolver; /** - * @param ValueFactory $valueFactory * @param Product $productResolver */ public function __construct( - ValueFactory $valueFactory, Product $productResolver ) { - $this->valueFactory = $valueFactory; $this->productResolver = $productResolver; } /** - * {@inheritDoc} + * @inheritdoc */ public function resolve( Field $field, @@ -51,14 +42,12 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { if (!isset($value['model'])) { - $result = function () { - return null; - }; - return $this->valueFactory->create($result); + throw new GraphQlInputException(__('"model" value should be specified')); } + $data = []; $productModel = $value['model']; $links = $productModel->getProductLinks(); foreach ($links as $link) { @@ -73,10 +62,6 @@ public function resolve( ]; } - $result = function () use ($data) { - return $data; - }; - - return $this->valueFactory->create($result); + return $data; } } diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php index a1e9160f9f506..fcf23dd9f682b 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php @@ -9,8 +9,6 @@ use Magento\Authorization\Model\UserContextInterface; 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\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Quote\Api\CartManagementInterface; @@ -32,11 +30,6 @@ class CreateEmptyCart implements ResolverInterface */ private $guestCartManagement; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @var QuoteIdToMaskedQuoteIdInterface */ @@ -50,28 +43,25 @@ class CreateEmptyCart implements ResolverInterface /** * @param CartManagementInterface $cartManagement * @param GuestCartManagementInterface $guestCartManagement - * @param ValueFactory $valueFactory * @param UserContextInterface $userContext * @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId */ public function __construct( CartManagementInterface $cartManagement, GuestCartManagementInterface $guestCartManagement, - ValueFactory $valueFactory, UserContextInterface $userContext, QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId ) { $this->cartManagement = $cartManagement; $this->guestCartManagement = $guestCartManagement; - $this->valueFactory = $valueFactory; $this->userContext = $userContext; $this->quoteIdToMaskedId = $quoteIdToMaskedId; } /** - * @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) { $customerId = $this->userContext->getUserId(); @@ -82,8 +72,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value $maskedQuoteId = $this->guestCartManagement->createEmptyCart(); } - return $this->valueFactory->create(function () use ($maskedQuoteId) { - return $maskedQuoteId; - }); + return $maskedQuoteId; } } diff --git a/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigDataProvider.php b/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigDataProvider.php index 0252d7898beee..92926c12e86d3 100644 --- a/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigDataProvider.php +++ b/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigDataProvider.php @@ -58,18 +58,6 @@ public function getStoreConfig() : array $store = $this->storeRepository->getById($storeId); $storeConfig = current($this->storeConfigManager->getStoreConfigs([$store->getCode()])); - return $this->hidrateStoreConfig($storeConfig); - } - - /** - * Transform StoreConfig object to in array format - * - * @param StoreConfigInterface $storeConfig - * @return array - */ - private function hidrateStoreConfig($storeConfig): array - { - /** @var StoreConfigInterface $storeConfig */ $storeConfigData = [ 'id' => $storeConfig->getId(), 'code' => $storeConfig->getCode(), @@ -88,7 +76,6 @@ private function hidrateStoreConfig($storeConfig): array 'secure_base_static_url' => $storeConfig->getSecureBaseStaticUrl(), 'secure_base_media_url' => $storeConfig->getSecureBaseMediaUrl() ]; - return $storeConfigData; } } diff --git a/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigResolver.php b/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigResolver.php index 8e5bf0120b8b8..39fcd1bf2792d 100644 --- a/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigResolver.php +++ b/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigResolver.php @@ -8,8 +8,6 @@ namespace Magento\StoreGraphQl\Model\Resolver; 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\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider; @@ -25,24 +23,16 @@ class StoreConfigResolver implements ResolverInterface private $storeConfigDataProvider; /** - * @var ValueFactory - */ - private $valueFactory; - - /** - * @param StoreConfigDataProvider $storeConfigsDataProvider - * @param ValueFactory $valueFactory + * @param StoreConfigDataProvider $storeConfigDataProvider */ public function __construct( - StoreConfigDataProvider $storeConfigsDataProvider, - ValueFactory $valueFactory + StoreConfigDataProvider $storeConfigDataProvider ) { - $this->valueFactory = $valueFactory; - $this->storeConfigDataProvider = $storeConfigsDataProvider; + $this->storeConfigDataProvider = $storeConfigDataProvider; } /** - * {@inheritdoc} + * @inheritdoc */ public function resolve( Field $field, @@ -50,14 +40,9 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ) : Value { + ) { $storeConfigData = $this->storeConfigDataProvider->getStoreConfig(); - - $result = function () use ($storeConfigData) { - return !empty($storeConfigData) ? $storeConfigData : []; - }; - - return $this->valueFactory->create($result); + return $storeConfigData; } } diff --git a/app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php b/app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php index 3f07edc601909..488f1281ce30f 100644 --- a/app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php +++ b/app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php @@ -7,10 +7,9 @@ namespace Magento\UrlRewriteGraphQl\Model\Resolver; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; 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\StoreManagerInterface; use Magento\UrlRewrite\Model\UrlFinderInterface; @@ -31,11 +30,6 @@ class UrlRewrite implements ResolverInterface */ private $storeManager; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @var CustomUrlLocatorInterface */ @@ -44,23 +38,20 @@ class UrlRewrite implements ResolverInterface /** * @param UrlFinderInterface $urlFinder * @param StoreManagerInterface $storeManager - * @param ValueFactory $valueFactory * @param CustomUrlLocatorInterface $customUrlLocator */ public function __construct( UrlFinderInterface $urlFinder, StoreManagerInterface $storeManager, - ValueFactory $valueFactory, CustomUrlLocatorInterface $customUrlLocator ) { $this->urlFinder = $urlFinder; $this->storeManager = $storeManager; - $this->valueFactory = $valueFactory; $this->customUrlLocator = $customUrlLocator; } /** - * {@inheritdoc} + * @inheritdoc */ public function resolve( Field $field, @@ -68,31 +59,27 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ) : Value { - $result = function () { - return null; - }; - - if (isset($args['url'])) { - $url = $args['url']; - if (substr($url, 0, 1) === '/' && $url !== '/') { - $url = ltrim($url, '/'); - } - $customUrl = $this->customUrlLocator->locateUrl($url); - $url = $customUrl ?: $url; - $urlRewrite = $this->findCanonicalUrl($url); - if ($urlRewrite) { - $urlRewriteReturnArray = [ - 'id' => $urlRewrite->getEntityId(), - 'canonical_url' => $urlRewrite->getTargetPath(), - 'type' => $this->sanitizeType($urlRewrite->getEntityType()) - ]; - $result = function () use ($urlRewriteReturnArray) { - return $urlRewriteReturnArray; - }; - } + ) { + if (!isset($args['url']) || empty(trim($args['url']))) { + throw new GraphQlInputException(__('"url" argument should be specified and not empty')); + } + + $result = null; + $url = $args['url']; + if (substr($url, 0, 1) === '/' && $url !== '/') { + $url = ltrim($url, '/'); + } + $customUrl = $this->customUrlLocator->locateUrl($url); + $url = $customUrl ?: $url; + $urlRewrite = $this->findCanonicalUrl($url); + if ($urlRewrite) { + $result = [ + 'id' => $urlRewrite->getEntityId(), + 'canonical_url' => $urlRewrite->getTargetPath(), + 'type' => $this->sanitizeType($urlRewrite->getEntityType()) + ]; } - return $this->valueFactory->create($result); + return $result; } /** diff --git a/dev/tests/api-functional/_files/Magento/TestModuleGraphQlQuery/Model/Resolver/Item.php b/dev/tests/api-functional/_files/Magento/TestModuleGraphQlQuery/Model/Resolver/Item.php index 6170c8dea3dd0..1731a974aaed3 100644 --- a/dev/tests/api-functional/_files/Magento/TestModuleGraphQlQuery/Model/Resolver/Item.php +++ b/dev/tests/api-functional/_files/Magento/TestModuleGraphQlQuery/Model/Resolver/Item.php @@ -9,27 +9,10 @@ use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Framework\GraphQl\Config\Element\Field; -use Magento\Framework\GraphQl\Query\PostFetchProcessorInterface; -use Magento\Framework\GraphQl\Query\Resolver\Value; -use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; use Magento\Framework\GraphQl\Query\ResolverInterface; class Item implements ResolverInterface { - /** - * @var ValueFactory - */ - private $valueFactory; - - /** - * @param ValueFactory $valueFactory - */ - public function __construct( - ValueFactory $valueFactory - ) { - $this->valueFactory = $valueFactory; - } - /** * @inheritdoc */ @@ -39,7 +22,7 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ) : Value { + ) { $id = 0; foreach ($args as $key => $argValue) { if ($key === "id") { @@ -50,11 +33,6 @@ public function resolve( 'item_id' => $id, 'name' => "itemName" ]; - - $result = function () use ($itemData) { - return $itemData; - }; - - return $this->valueFactory->create($result); + return $itemData; } } diff --git a/dev/tests/api-functional/_files/Magento/TestModuleGraphQlQueryExtension/Model/Resolver/IntegerList.php b/dev/tests/api-functional/_files/Magento/TestModuleGraphQlQueryExtension/Model/Resolver/IntegerList.php index 878212f494218..34dc92fcbbaa4 100644 --- a/dev/tests/api-functional/_files/Magento/TestModuleGraphQlQueryExtension/Model/Resolver/IntegerList.php +++ b/dev/tests/api-functional/_files/Magento/TestModuleGraphQlQueryExtension/Model/Resolver/IntegerList.php @@ -9,8 +9,6 @@ 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; /** @@ -19,20 +17,7 @@ class IntegerList implements ResolverInterface { /** - * @var ValueFactory - */ - private $valueFactory; - - /** - * @param ValueFactory $valueFactory - */ - public function __construct(ValueFactory $valueFactory) - { - $this->valueFactory = $valueFactory; - } - - /** - * {@inheritdoc} + * @inheritdoc */ public function resolve( Field $field, @@ -40,21 +25,14 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { if (!isset($value['item_id'])) { - return $this->valueFactory->create(function () { - return null; - }); + return null; } $itemId = $value['item_id']; $resultData = [$itemId + 1, $itemId + 2, $itemId + 3]; - - $result = function () use ($resultData) { - return $resultData; - }; - - return $this->valueFactory->create($result); + return $resultData; } } diff --git a/lib/internal/Magento/Framework/GraphQl/Query/ResolverInterface.php b/lib/internal/Magento/Framework/GraphQl/Query/ResolverInterface.php index ec59f132cc7c9..295113a98e465 100644 --- a/lib/internal/Magento/Framework/GraphQl/Query/ResolverInterface.php +++ b/lib/internal/Magento/Framework/GraphQl/Query/ResolverInterface.php @@ -25,7 +25,7 @@ interface ResolverInterface * @param array|null $value * @param array|null $args * @throws \Exception - * @return Value + * @return mixed|Value */ public function resolve( Field $field, @@ -33,5 +33,5 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ) : Value; + ); } From 5fdbfc0ac4ccc3c65fe0f5d33611867113c7b38a Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 11 Sep 2018 18:26:36 +0300 Subject: [PATCH 08/11] GraphQL-152: Allow scalars as resolver return type --- .../Magento/BundleGraphQl/Model/Resolver/BundleItems.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/BundleGraphQl/Model/Resolver/BundleItems.php b/app/code/Magento/BundleGraphQl/Model/Resolver/BundleItems.php index a402ee6d4c299..b67bd69ecf924 100644 --- a/app/code/Magento/BundleGraphQl/Model/Resolver/BundleItems.php +++ b/app/code/Magento/BundleGraphQl/Model/Resolver/BundleItems.php @@ -39,16 +39,16 @@ class BundleItems implements ResolverInterface /** * @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; } /** From 4793553bff78989c06d4e7bfd321ff5c786eeb4d Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 11 Sep 2018 18:44:48 +0300 Subject: [PATCH 09/11] GraphQL-172: GraphQL modules delivery -- add block_rollback fixture --- .../Magento/Cms/_files/block_rollback.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Cms/_files/block_rollback.php diff --git a/dev/tests/integration/testsuite/Magento/Cms/_files/block_rollback.php b/dev/tests/integration/testsuite/Magento/Cms/_files/block_rollback.php new file mode 100644 index 0000000000000..9214dd543bd31 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Cms/_files/block_rollback.php @@ -0,0 +1,30 @@ +get(BlockRepositoryInterface::class); + +/** @var SearchCriteriaBuilder $searchCriteriaBuilder */ +$searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class); +$searchCriteria = $searchCriteriaBuilder->addFilter(BlockInterface::IDENTIFIER, 'fixture_block') + ->create(); +$result = $blockRepository->getList($searchCriteria); + +/** + * Tests which are wrapped with MySQL transaction clear all data by transaction rollback. + * In that case there is "if" which checks that "fixture_block" still exists in database. + */ +foreach ($result->getItems() as $item) { + $blockRepository->delete($item); +} From 39fd0f9c02e5cbf7eb81155cf999dc32a908e5fa Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 11 Sep 2018 19:36:03 +0300 Subject: [PATCH 10/11] GraphQL-172: GraphQL modules delivery --- .../GraphQl/Catalog/BreadcrumbsTest.php | 175 ------------------ 1 file changed, 175 deletions(-) delete mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/BreadcrumbsTest.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/BreadcrumbsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/BreadcrumbsTest.php deleted file mode 100644 index d0879ae5864ef..0000000000000 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/BreadcrumbsTest.php +++ /dev/null @@ -1,175 +0,0 @@ -get(CollectionFactory::class)->create(); - $categoryCollection->addAttributeToFilter('name', ['eq' => 'Category 1.1.1']); - $selectedCategoryId = (int)$categoryCollection->getFirstItem()->getId(); - $query = - <<graphQlQuery($query); - $this->assertArrayHasKey('category', $response); - $this->assertArrayHasKey('breadcrumbs', $response['category']); - $this->assertBaseFields($selectedCategoryId, $response); - } - - /** - * Verify the fields of CMS Block selected by identifiers. - * - * @magentoApiDataFixture Magento/Catalog/_files/category_tree.php - * @return void - */ - public function testGetBreadcrumbsForNonExistingCategory(): void - { - $query = - <<graphQlQuery($query); - $this->assertArrayHasKey('category', $response); - $this->assertNull( - $response['category'], - 'Value of "category" field must be NULL if requested category doesn\'t exist' - ); - $this->assertCount( - 1, - $response, - 'There should be only "category" field if requested category doesn\'t exist ' - ); - } - - /** - * Asserts the equality of the response fields to the fields given in assertion map. - * Assert that values of the fields are different from NULL - * - * @param array $actualResponse - * @param array $assertionMap - * @return void - */ - private function assertResponseFields(array $actualResponse, array $assertionMap): void - { - foreach ($assertionMap as $key => $assertionData) { - $expectedValue = isset($assertionData['expected_value']) - ? $assertionData['expected_value'] - : $assertionData; - $responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key; - $this->assertNotNull( - $expectedValue, - "Value of '{$responseField}' field must not be NULL" - ); - $this->assertEquals( - $expectedValue[$key], - $actualResponse[$responseField], - "Value of '{$responseField}' field in response does not match expected value: " - . var_export($expectedValue, true) - ); - } - } - - /** - * Get breadcrumbs for given category. - * - * @param Category $category - * @return array - */ - private function getBreadcrumbs(Category $category): array - { - $breadcrumbs = []; - $rootId = Bootstrap::getObjectManager()->get(StoreManagerInterface::class) - ->getStore() - ->getRootCategoryId(); - foreach ($category->getParentCategories() as $parentCategory) { - if ($parentCategory->getId() !== $rootId) { - $breadcrumbs[] = [ - 'category_id' => $parentCategory->getId(), - 'category_name' => $parentCategory->getName(), - 'category_level' => $parentCategory->getLevel(), - 'category_url_key' => $parentCategory->getUrlKey(), - ]; - } - } - - return $breadcrumbs; - } - - /** - * Asserts base fields - * - * @param int $categoryId - * @param array $actualResponse - * @return void - */ - private function assertBaseFields(int $categoryId, array $actualResponse): void - { - $category = Bootstrap::getObjectManager()->create(Category::class)->load($categoryId); - $assertionMap = [ - [ - 'response_field' => 'category', - 'expected_value' => - [ - [ - 'name' => $category->getName(), - 'breadcrumbs' => $this->getBreadcrumbs($category->getParentCategory()), - ], - - ], - ], - ]; - - /** - * @param array $actualResponse - * @param array $assertionMap ['response_field_name' => 'response_field_value', ...] - * OR [['response_field' => $field, 'expected_value' => $value], ...] - */ - $this->assertResponseFields($actualResponse, $assertionMap); - } -} From 91863728e6a3b7d35867d4e6b3afbeb387091b44 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 11 Sep 2018 20:29:09 +0300 Subject: [PATCH 11/11] GraphQL-172: GraphQL modules delivery --- .../testsuite/Magento/GraphQl/Cms/CmsBlockTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php index 41bb98d24bfec..d8e06fd08385c 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php @@ -64,6 +64,8 @@ public function testGetCmsBlocksByIdentifiers() /** * Verify the message when CMS Block is disabled + * + * @magentoApiDataFixture Magento/Cms/_files/block.php */ public function testGetDisabledCmsBlockByIdentifiers() {