From 0cdfdcb5676bd24a3ab2562ddd59501868c887c1 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Wed, 1 Aug 2018 18:04:37 +0200 Subject: [PATCH 01/19] Added HTML renderer for description and short description --- .../Resolver/Product/ProductHtmlAttribute.php | 72 +++++++++++++++++++ .../CatalogGraphQl/etc/schema.graphqls | 6 +- 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductHtmlAttribute.php diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductHtmlAttribute.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductHtmlAttribute.php new file mode 100644 index 00000000000..18d15088e66 --- /dev/null +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductHtmlAttribute.php @@ -0,0 +1,72 @@ +valueFactory = $valueFactory; + $this->outputHelper = $outputHelper; + } + + /** + * {@inheritdoc} + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ): Value { + if (!isset($value['model'])) { + $result = function () { + return null; + }; + return $this->valueFactory->create($result); + } + + /* @var $product Product */ + $product = $value['model']; + $fieldName = $field->getName(); + $renderedValue = $this->outputHelper->productAttribute($product, $product->getData($fieldName), $fieldName); + $result = function () use ($renderedValue) { + return $renderedValue; + }; + + return $this->valueFactory->create($result); + } +} diff --git a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls index 9235ec271a3..f63c1a96762 100644 --- a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls @@ -248,8 +248,8 @@ interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\ id: Int @doc(description: "The ID number assigned to the product") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\EntityIdToId") name: String @doc(description: "The product name. Customers use this name to identify the product.") sku: String @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer") - description: String @doc(description: "Detailed information about the product. The value can include simple HTML tags.") - short_description: String @doc(description: "A short description of the product. Its use depends on the theme.") + description: String @doc(description: "Detailed information about the product. The value can include simple HTML tags.") @resolver(class: "\\Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductHtmlAttribute") + short_description: String @doc(description: "A short description of the product. Its use depends on the theme.") @resolver(class: "\\Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductHtmlAttribute") special_price: Float @doc(description: "The discounted price of the product") special_from_date: String @doc(description: "The beginning date that a product has a special price") special_to_date: String @doc(description: "The end date that a product has a special price") @@ -548,6 +548,6 @@ type SortField { } type SortFields @doc(description: "SortFields contains a default value for sort fields and all available sort fields") { - default: String @doc(description: "Default value of sort fields") + default: String @doc(description: "Default value of sort fields") options: [SortField] @doc(description: "Available sort fields") } From 6638f7eb8a5754ca71e33220d468f365c98c6fa4 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Wed, 8 Aug 2018 12:26:30 +0200 Subject: [PATCH 02/19] Api-functional tests added --- .../ProductWithDescriptionDirectivesTest.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductWithDescriptionDirectivesTest.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductWithDescriptionDirectivesTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductWithDescriptionDirectivesTest.php new file mode 100644 index 00000000000..cb02b92415d --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductWithDescriptionDirectivesTest.php @@ -0,0 +1,63 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + /** + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/Cms/_files/block.php + */ + public function testHtmlDirectivesRendered() + { + $productSku = 'simple'; + $cmsBlockId = 'fixture_block'; + $assertionCmsBlockText = 'Fixture Block Title'; + + /** @var ProductRepositoryInterface $productRepository */ + $productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class); + /** @var ProductInterface $product */ + $product = $productRepository->get($productSku, false, null, true); + $product->setDescription('Test: {{block id="' . $cmsBlockId . '"}}'); + $product->setShortDescription('Test: {{block id="' . $cmsBlockId . '"}}'); + $productRepository->save($product); + + $query = <<graphQlQuery($query); + + self::assertContains($assertionCmsBlockText, $response['products']['items'][0]['description']); + self::assertContains($assertionCmsBlockText, $response['products']['items'][0]['short_description']); + } +} From 4fbb2aee99f5e1295f00e7a71ab36049ecf0abb2 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Thu, 9 Aug 2018 12:19:02 +0200 Subject: [PATCH 03/19] Check that rendered values do not contain directives --- .../GraphQl/Catalog/ProductWithDescriptionDirectivesTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductWithDescriptionDirectivesTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductWithDescriptionDirectivesTest.php index cb02b92415d..8e9bc4dfa28 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductWithDescriptionDirectivesTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductWithDescriptionDirectivesTest.php @@ -58,6 +58,8 @@ public function testHtmlDirectivesRendered() $response = $this->graphQlQuery($query); self::assertContains($assertionCmsBlockText, $response['products']['items'][0]['description']); + self::assertNotContains('{{block id', $response['products']['items'][0]['description']); self::assertContains($assertionCmsBlockText, $response['products']['items'][0]['short_description']); + self::assertNotContains('{{block id', $response['products']['items'][0]['short_description']); } } From 527e4febe49ff6c2ab3b42ddabf798307f0e7222 Mon Sep 17 00:00:00 2001 From: Andrey Zabara Date: Tue, 28 Aug 2018 14:45:22 +0300 Subject: [PATCH 04/19] GraphQl-129: Retrieve Customer token --- .../Account/GenerateCustomerToken.php | 70 +++++++++++++++++++ .../CustomerGraphQl/etc/schema.graphqls | 8 +++ 2 files changed, 78 insertions(+) create mode 100644 app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php new file mode 100644 index 00000000000..7a76caddfff --- /dev/null +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php @@ -0,0 +1,70 @@ +userContext = $userContext; + $this->customerTokenService = $customerTokenService; + $this->valueFactory = $valueFactory; + } + + /** + * @inheritdoc + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ): Value { + + $token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']); + //TODO: exception + $result = function () use ($token) { + return !empty($token) ? $token : ''; + }; + return $this->valueFactory->create($result); + } +} diff --git a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls index 91b7ef1f9be..76268b5622b 100644 --- a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls @@ -5,6 +5,14 @@ type Query { customer: Customer @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\Customer") @doc(description: "The customer query returns information about a customer account") } +type Mutation { + generateCustomerToken(email: String!, password: String!): GenerateCustomerTokenOutput! @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\GenerateCustomerToken") @doc(description:"Retrieve Customer token") +} + +type GenerateCustomerTokenOutput { + token: String! @doc(description: "The customer token") +} + type Customer @doc(description: "Customer defines the customer name and address and other details") { created_at: String @doc(description: "Timestamp indicating when the account was created") group_id: Int @doc(description: "The group assigned to the user. Default values are 0 (Not logged in), 1 (General), 2 (Wholesale), and 3 (Retailer)") From 8771f41e6191d3a7e26cca0413740524f1106b23 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Tue, 4 Sep 2018 18:54:33 +0200 Subject: [PATCH 05/19] Quote masked id creation logic moved to create cart resolver --- .../Quote/Model/QuoteIdToMaskedQuoteId.php | 17 ++++++++++++---- .../Model/Resolver/Cart/CreateEmptyCart.php | 20 ++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php b/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php index 5ddadfc22f5..3c366fcc4ab 100644 --- a/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php +++ b/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php @@ -8,6 +8,7 @@ namespace Magento\Quote\Model; use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResource; class QuoteIdToMaskedQuoteId implements QuoteIdToMaskedQuoteIdInterface { @@ -15,22 +16,29 @@ class QuoteIdToMaskedQuoteId implements QuoteIdToMaskedQuoteIdInterface * @var QuoteIdMaskFactory */ private $quoteIdMaskFactory; - /** * @var CartRepositoryInterface */ private $cartRepository; + /** + * @var QuoteIdMaskResource + */ + private $quoteIdMaskResource; + /** * @param QuoteIdMaskFactory $quoteIdMaskFactory * @param CartRepositoryInterface $cartRepository + * @param QuoteIdMaskResource $quoteIdMaskResource */ public function __construct( QuoteIdMaskFactory $quoteIdMaskFactory, - CartRepositoryInterface $cartRepository + CartRepositoryInterface $cartRepository, + QuoteIdMaskResource $quoteIdMaskResource ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; $this->cartRepository = $cartRepository; + $this->quoteIdMaskResource = $quoteIdMaskResource; } /** @@ -42,8 +50,9 @@ public function execute(int $quoteId): string $this->cartRepository->get($quoteId); $quoteIdMask = $this->quoteIdMaskFactory->create(); - $quoteIdMask->setQuoteId($quoteId)->save(); + $this->quoteIdMaskResource->load($quoteIdMask, $quoteId, 'quote_id'); + $maskedId = $quoteIdMask->getMaskedId() ?? ''; - return $quoteIdMask->getMaskedId(); + return $maskedId; } } diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php index 18c70ccceca..1f570191358 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php @@ -16,6 +16,7 @@ use Magento\Quote\Api\CartManagementInterface; use Magento\Quote\Api\GuestCartManagementInterface; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; +use Magento\Quote\Model\QuoteIdMaskFactory; /** * @inheritdoc @@ -26,7 +27,6 @@ class CreateEmptyCart implements ResolverInterface * @var CartManagementInterface */ private $cartManagement; - /** * @var GuestCartManagementInterface */ @@ -47,25 +47,33 @@ class CreateEmptyCart implements ResolverInterface */ private $userContext; + /** + * @var QuoteIdMaskFactory + */ + private $quoteIdMaskFactory; + /** * @param CartManagementInterface $cartManagement * @param GuestCartManagementInterface $guestCartManagement * @param ValueFactory $valueFactory * @param UserContextInterface $userContext * @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId + * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( CartManagementInterface $cartManagement, GuestCartManagementInterface $guestCartManagement, ValueFactory $valueFactory, UserContextInterface $userContext, - QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId + QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId, + QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->cartManagement = $cartManagement; $this->guestCartManagement = $guestCartManagement; $this->valueFactory = $valueFactory; $this->userContext = $userContext; $this->quoteIdToMaskedId = $quoteIdToMaskedId; + $this->quoteIdMaskFactory = $quoteIdMaskFactory; } /** @@ -77,7 +85,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value if (null !== $customerId) { $quoteId = $this->cartManagement->createEmptyCartForCustomer($customerId); - $maskedQuoteId = $this->quoteIdToMaskedId->execute($quoteId); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quoteId); + + if (empty($maskedQuoteId)) { + $quoteIdMask = $this->quoteIdMaskFactory->create(); + $quoteIdMask->setQuoteId($quoteId)->save(); + $maskedQuoteId = $quoteIdMask->getMaskedId(); + } } else { $maskedQuoteId = $this->guestCartManagement->createEmptyCart(); } From ea9b2a8a73da00df665da807b830615c129945fc Mon Sep 17 00:00:00 2001 From: Pablo Fantini Date: Sat, 8 Sep 2018 15:47:11 -0300 Subject: [PATCH 06/19] GraphQL-129: Change generate token schema and add graphql exception --- .../Customer/Account/GenerateCustomerToken.php | 18 +++++++++++------- .../CustomerGraphQl/etc/schema.graphqls | 6 +----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php index 7a76caddfff..466aad1c034 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php @@ -59,12 +59,16 @@ public function resolve( array $value = null, array $args = null ): Value { - - $token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']); - //TODO: exception - $result = function () use ($token) { - return !empty($token) ? $token : ''; - }; - return $this->valueFactory->create($result); + try { + $token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']); + $result = function () use ($token) { + return !empty($token) ? $token : ''; + }; + return $this->valueFactory->create($result); + }catch (\Magento\Framework\Exception\AuthenticationException $e){ + throw new GraphQlAuthorizationException( + __($e->getMessage()) + ); + } } } diff --git a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls index 76268b5622b..0aaa869a664 100644 --- a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls @@ -6,11 +6,7 @@ type Query { } type Mutation { - generateCustomerToken(email: String!, password: String!): GenerateCustomerTokenOutput! @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\GenerateCustomerToken") @doc(description:"Retrieve Customer token") -} - -type GenerateCustomerTokenOutput { - token: String! @doc(description: "The customer token") + generateCustomerToken(email: String!, password: String!): String! @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\GenerateCustomerToken") @doc(description:"Retrieve Customer token") } type Customer @doc(description: "Customer defines the customer name and address and other details") { From ca0c135c56511a3b67319f54f1ce39894c764e55 Mon Sep 17 00:00:00 2001 From: Pablo Fantini Date: Tue, 11 Sep 2018 19:48:01 -0300 Subject: [PATCH 07/19] GraphQL-129. Add generate customer token test --- .../Customer/GenerateCustomerTokenTest.php | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php new file mode 100644 index 00000000000..6aa970037fe --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php @@ -0,0 +1,66 @@ +graphQlQuery($mutation); + $this->assertArrayHasKey('generateCustomerToken', $response); + $this->assertInternalType('string', $response['generateCustomerToken']); + } + + /** + * Verify customer with invalid credentials + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testGenerateCustomerTokenWithInvalidCredentials() + { + $userName = 'customer@example.com'; + $password = 'bad-password'; + + $mutation + = <<expectException(\Exception::class); + $this->expectExceptionMessage('GraphQL response contains errors: ' . + 'The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later.'); + $this->graphQlQuery($mutation); + } +} From c0d1b7b7400dd53e78e15b42d68c6bf4df46b195 Mon Sep 17 00:00:00 2001 From: Pablo Fantini Date: Wed, 12 Sep 2018 12:15:23 -0300 Subject: [PATCH 08/19] GrapgQL-129: Add composer dependency and fix codestyle issues --- .../Customer/Account/GenerateCustomerToken.php | 16 ++++------------ app/code/Magento/CustomerGraphQl/composer.json | 1 + .../Customer/GenerateCustomerTokenTest.php | 4 ++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php index 466aad1c034..15012ca1364 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php @@ -7,11 +7,10 @@ namespace Magento\CustomerGraphQl\Model\Resolver\Customer\Account; -use Magento\Authorization\Model\UserContextInterface; use Magento\Integration\Api\CustomerTokenServiceInterface; -use Magento\Customer\Model\Customer; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; +use Magento\Framework\Exception\AuthenticationException; use Magento\Framework\GraphQl\Query\Resolver\Value; use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; use Magento\Framework\GraphQl\Query\ResolverInterface; @@ -19,10 +18,6 @@ class GenerateCustomerToken implements ResolverInterface { - /** - * @var UserContextInterface - */ - private $userContext; /** * @var CustomerTokenServiceInterface @@ -35,18 +30,15 @@ class GenerateCustomerToken implements ResolverInterface private $valueFactory; /** - * @param UserContextInterface $userContext * @param CustomerTokenServiceInterface $customerTokenService - * @param ValueFactory $valueFactory + * @param ValueFactory $valueFactory */ public function __construct( - UserContextInterface $userContext, CustomerTokenServiceInterface $customerTokenService, ValueFactory $valueFactory ) { - $this->userContext = $userContext; $this->customerTokenService = $customerTokenService; - $this->valueFactory = $valueFactory; + $this->valueFactory = $valueFactory; } /** @@ -65,7 +57,7 @@ public function resolve( return !empty($token) ? $token : ''; }; return $this->valueFactory->create($result); - }catch (\Magento\Framework\Exception\AuthenticationException $e){ + } catch (AuthenticationException $e) { throw new GraphQlAuthorizationException( __($e->getMessage()) ); diff --git a/app/code/Magento/CustomerGraphQl/composer.json b/app/code/Magento/CustomerGraphQl/composer.json index 290d925215e..c26c83c95be 100644 --- a/app/code/Magento/CustomerGraphQl/composer.json +++ b/app/code/Magento/CustomerGraphQl/composer.json @@ -6,6 +6,7 @@ "php": "~7.1.3||~7.2.0", "magento/module-customer": "*", "magento/module-authorization": "*", + "magento/module-integration": "*", "magento/framework": "*" }, "suggest": { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php index 6aa970037fe..44b7925ec4e 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php @@ -59,8 +59,8 @@ public function testGenerateCustomerTokenWithInvalidCredentials() MUTATION; $this->expectException(\Exception::class); - $this->expectExceptionMessage('GraphQL response contains errors: ' . - 'The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later.'); + $this->expectExceptionMessage('GraphQL response contains errors: The account sign-in' . ' ' . + 'was incorrect or your account is disabled temporarily. Please wait and try again later.'); $this->graphQlQuery($mutation); } } From e97301d483ed196eef7b7ac33f3a26bc1d737ed9 Mon Sep 17 00:00:00 2001 From: Pablo Fantini Date: Fri, 14 Sep 2018 00:04:48 -0300 Subject: [PATCH 09/19] GraphQL-129: Change resolve to return array, update schema and test --- .../Customer/Account/GenerateCustomerToken.php | 6 ++++-- .../Magento/CustomerGraphQl/etc/schema.graphqls | 6 +++++- .../Customer/GenerateCustomerTokenTest.php | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php index 15012ca1364..8737e09e085 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php @@ -16,9 +16,11 @@ use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; +/** + * Customers Token resolver, used for GraphQL request processing. + */ class GenerateCustomerToken implements ResolverInterface { - /** * @var CustomerTokenServiceInterface */ @@ -54,7 +56,7 @@ public function resolve( try { $token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']); $result = function () use ($token) { - return !empty($token) ? $token : ''; + return !empty($token) ? ['token' => $token] : ''; }; return $this->valueFactory->create($result); } catch (AuthenticationException $e) { diff --git a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls index 0aaa869a664..2d5819457e3 100644 --- a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls @@ -6,7 +6,11 @@ type Query { } type Mutation { - generateCustomerToken(email: String!, password: String!): String! @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\GenerateCustomerToken") @doc(description:"Retrieve Customer token") + generateCustomerToken(email: String!, password: String!): CustomerToken @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\GenerateCustomerToken") @doc(description:"Retrieve Customer token") +} + +type CustomerToken { + token: String @doc(description: "The new customer token") } type Customer @doc(description: "Customer defines the customer name and address and other details") { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php index 44b7925ec4e..90e15652ae0 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php @@ -8,10 +8,14 @@ namespace Magento\GraphQl\Customer; use Magento\TestFramework\TestCase\GraphQlAbstract; +use PHPUnit\Framework\TestResult; +/** + * Class GenerateCustomerTokenTest + * @package Magento\GraphQl\Customer + */ class GenerateCustomerTokenTest extends GraphQlAbstract { - /** * Verify customer token with valid credentials * @@ -29,13 +33,15 @@ public function testGenerateCustomerValidToken() generateCustomerToken( email: "{$userName}" password: "{$password}" - ) + ) { + token + } } MUTATION; $response = $this->graphQlQuery($mutation); $this->assertArrayHasKey('generateCustomerToken', $response); - $this->assertInternalType('string', $response['generateCustomerToken']); + $this->assertInternalType('array', $response['generateCustomerToken']); } /** @@ -54,7 +60,9 @@ public function testGenerateCustomerTokenWithInvalidCredentials() generateCustomerToken( email: "{$userName}" password: "{$password}" - ) + ) { + token + } } MUTATION; From 85cd23901cd2e4cbdd184a172358314f7094777e Mon Sep 17 00:00:00 2001 From: TomashKhamlai Date: Fri, 14 Sep 2018 16:00:08 +0300 Subject: [PATCH 10/19] Remove PHPMD directive --- .../Magento/GraphQl/Customer/GenerateCustomerTokenTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php index 90e15652ae0..ae28e23a28b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php @@ -20,7 +20,6 @@ class GenerateCustomerTokenTest extends GraphQlAbstract * Verify customer token with valid credentials * * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testGenerateCustomerValidToken() { @@ -46,8 +45,6 @@ public function testGenerateCustomerValidToken() /** * Verify customer with invalid credentials - * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testGenerateCustomerTokenWithInvalidCredentials() { From 21e719c2f7062652b8b1d564474bac1426242633 Mon Sep 17 00:00:00 2001 From: TomashKhamlai Date: Fri, 14 Sep 2018 16:26:06 +0300 Subject: [PATCH 11/19] Simplify code to avoid complexity of getting just one string --- .../Resolver/Customer/Account/GenerateCustomerToken.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php index 8737e09e085..d20f0208348 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php @@ -52,13 +52,10 @@ public function resolve( ResolveInfo $info, array $value = null, array $args = null - ): Value { + ) { try { $token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']); - $result = function () use ($token) { - return !empty($token) ? ['token' => $token] : ''; - }; - return $this->valueFactory->create($result); + return !empty($token) ? ['token' => $token] : ''; } catch (AuthenticationException $e) { throw new GraphQlAuthorizationException( __($e->getMessage()) From ad388f6e1ed3ee97c27220066938c9efa9561837 Mon Sep 17 00:00:00 2001 From: TomashKhamlai Date: Fri, 14 Sep 2018 16:33:02 +0300 Subject: [PATCH 12/19] Remove usage of Value Factory and optimize imports --- .../Account/GenerateCustomerToken.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php index d20f0208348..3e188f6c8f2 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php @@ -7,14 +7,12 @@ namespace Magento\CustomerGraphQl\Model\Resolver\Customer\Account; -use Magento\Integration\Api\CustomerTokenServiceInterface; +use Magento\Framework\Exception\AuthenticationException; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; -use Magento\Framework\Exception\AuthenticationException; -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\Integration\Api\CustomerTokenServiceInterface; /** * Customers Token resolver, used for GraphQL request processing. @@ -26,21 +24,14 @@ class GenerateCustomerToken implements ResolverInterface */ private $customerTokenService; - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @param CustomerTokenServiceInterface $customerTokenService - * @param ValueFactory $valueFactory */ public function __construct( - CustomerTokenServiceInterface $customerTokenService, - ValueFactory $valueFactory + CustomerTokenServiceInterface $customerTokenService + ) { $this->customerTokenService = $customerTokenService; - $this->valueFactory = $valueFactory; } /** @@ -55,7 +46,7 @@ public function resolve( ) { try { $token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']); - return !empty($token) ? ['token' => $token] : ''; + return ['token' => $token]; } catch (AuthenticationException $e) { throw new GraphQlAuthorizationException( __($e->getMessage()) From 277fe084c5af746dbdc254d9ffb5929c175a0848 Mon Sep 17 00:00:00 2001 From: TomashKhamlai Date: Fri, 14 Sep 2018 16:51:57 +0300 Subject: [PATCH 13/19] Add checks for input arguments --- .../Resolver/Customer/Account/GenerateCustomerToken.php | 7 ++++++- app/code/Magento/CustomerGraphQl/etc/schema.graphqls | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php index 3e188f6c8f2..b756a96411a 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php @@ -29,7 +29,6 @@ class GenerateCustomerToken implements ResolverInterface */ public function __construct( CustomerTokenServiceInterface $customerTokenService - ) { $this->customerTokenService = $customerTokenService; } @@ -45,6 +44,12 @@ public function resolve( array $args = null ) { try { + if (!isset($args['email'])) { + throw new GraphQlInputException(__('"email" value should be specified')); + } + if (!isset($args['password'])) { + throw new GraphQlInputException(__('"password" value should be specified')); + } $token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']); return ['token' => $token]; } catch (AuthenticationException $e) { diff --git a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls index 2d5819457e3..2fbf2b12193 100644 --- a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls @@ -10,7 +10,7 @@ type Mutation { } type CustomerToken { - token: String @doc(description: "The new customer token") + token: String @doc(description: "The customer token") } type Customer @doc(description: "Customer defines the customer name and address and other details") { From c7635146f3d70e8b69230ac8d89493d88367cd4d Mon Sep 17 00:00:00 2001 From: Pablo Fantini Date: Sat, 15 Sep 2018 23:27:23 -0300 Subject: [PATCH 14/19] GraphQL-80: rename canonical_url to relative_url and fix covered test --- .../Model/Resolver/UrlRewrite.php | 2 +- .../UrlRewriteGraphQl/etc/schema.graphqls | 6 +-- .../GraphQl/UrlRewrite/UrlResolverTest.php | 54 ++++++++++++------- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php b/app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php index 488f1281ce3..5bdaf362725 100644 --- a/app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php +++ b/app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php @@ -75,7 +75,7 @@ public function resolve( if ($urlRewrite) { $result = [ 'id' => $urlRewrite->getEntityId(), - 'canonical_url' => $urlRewrite->getTargetPath(), + 'relative_url' => $urlRewrite->getTargetPath(), 'type' => $this->sanitizeType($urlRewrite->getEntityType()) ]; } diff --git a/app/code/Magento/UrlRewriteGraphQl/etc/schema.graphqls b/app/code/Magento/UrlRewriteGraphQl/etc/schema.graphqls index 38f1d9c6563..e9a39617774 100644 --- a/app/code/Magento/UrlRewriteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/UrlRewriteGraphQl/etc/schema.graphqls @@ -1,14 +1,14 @@ # Copyright © Magento, Inc. All rights reserved. # See COPYING.txt for license details. -type EntityUrl @doc(description: "EntityUrl is an output object containing the `id`, `canonical_url`, and `type` attributes") { +type EntityUrl @doc(description: "EntityUrl is an output object containing the `id`, `relative_url`, and `type` attributes") { id: Int @doc(description: "The ID assigned to the object associated with the specified url. This could be a product ID, category ID, or page ID.") - canonical_url: String @doc(description: "The internal relative URL. If the specified url is a redirect, the query returns the redirected URL, not the original.") + relative_url: String @doc(description: "The internal relative URL. If the specified url is a redirect, the query returns the redirected URL, not the original.") type: UrlRewriteEntityTypeEnum @doc(description: "One of PRODUCT, CATEGORY, or CMS_PAGE.") } type Query { - urlResolver(url: String!): EntityUrl @resolver(class: "Magento\\UrlRewriteGraphQl\\Model\\Resolver\\UrlRewrite") @doc(description: "The urlResolver query returns the canonical URL for a specified product, category or CMS page") + urlResolver(url: String!): EntityUrl @resolver(class: "Magento\\UrlRewriteGraphQl\\Model\\Resolver\\UrlRewrite") @doc(description: "The urlResolver query returns the relative URL for a specified product, category or CMS page") } enum UrlRewriteEntityTypeEnum { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/UrlRewrite/UrlResolverTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/UrlRewrite/UrlResolverTest.php index 0bd24ee7bc8..4c964265e9f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/UrlRewrite/UrlResolverTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/UrlRewrite/UrlResolverTest.php @@ -12,6 +12,9 @@ use Magento\TestFramework\ObjectManager; use Magento\TestFramework\TestCase\GraphQlAbstract; use Magento\UrlRewrite\Model\UrlFinderInterface; +use Magento\Cms\Helper\Page as PageHelper; +use Magento\Store\Model\ScopeInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; /** * Test the GraphQL endpoint's URLResolver query to verify canonical URL's are correctly returned. @@ -28,7 +31,7 @@ protected function setUp() } /** - * Tests if target_path(canonical_url) is resolved for Product entity + * Tests if target_path(relative_url) is resolved for Product entity * * @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php */ @@ -57,7 +60,7 @@ public function testProductUrlResolver() urlResolver(url:"{$urlPath}") { id - canonical_url + relative_url type } } @@ -65,12 +68,12 @@ public function testProductUrlResolver() $response = $this->graphQlQuery($query); $this->assertArrayHasKey('urlResolver', $response); $this->assertEquals($product->getEntityId(), $response['urlResolver']['id']); - $this->assertEquals($targetPath, $response['urlResolver']['canonical_url']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']); } /** - * Tests the use case where canonical_url is provided as resolver input in the Query + * Tests the use case where relative_url is provided as resolver input in the Query * * @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php */ @@ -101,7 +104,7 @@ public function testProductUrlWithCanonicalUrlInput() urlResolver(url:"{$canonicalPath}") { id - canonical_url + relative_url type } } @@ -109,7 +112,7 @@ public function testProductUrlWithCanonicalUrlInput() $response = $this->graphQlQuery($query); $this->assertArrayHasKey('urlResolver', $response); $this->assertEquals($product->getEntityId(), $response['urlResolver']['id']); - $this->assertEquals($targetPath, $response['urlResolver']['canonical_url']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']); } @@ -144,7 +147,7 @@ public function testCategoryUrlResolver() urlResolver(url:"{$urlPath2}") { id - canonical_url + relative_url type } } @@ -152,7 +155,7 @@ public function testCategoryUrlResolver() $response = $this->graphQlQuery($query); $this->assertArrayHasKey('urlResolver', $response); $this->assertEquals($categoryId, $response['urlResolver']['id']); - $this->assertEquals($targetPath, $response['urlResolver']['canonical_url']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']); } @@ -180,14 +183,14 @@ public function testCMSPageUrlResolver() urlResolver(url:"{$requestPath}") { id - canonical_url + relative_url type } } QUERY; $response = $this->graphQlQuery($query); $this->assertEquals($cmsPageId, $response['urlResolver']['id']); - $this->assertEquals($targetPath, $response['urlResolver']['canonical_url']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals(strtoupper(str_replace('-', '_', $expectedEntityType)), $response['urlResolver']['type']); } @@ -223,7 +226,7 @@ public function testProductUrlRewriteResolver() urlResolver(url:"{$urlPath}") { id - canonical_url + relative_url type } } @@ -231,7 +234,7 @@ public function testProductUrlRewriteResolver() $response = $this->graphQlQuery($query); $this->assertArrayHasKey('urlResolver', $response); $this->assertEquals($product->getEntityId(), $response['urlResolver']['id']); - $this->assertEquals($targetPath, $response['urlResolver']['canonical_url']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']); } @@ -263,7 +266,7 @@ public function testInvalidUrlResolverInput() urlResolver(url:"{$urlPath}") { id - canonical_url + relative_url type } } @@ -304,7 +307,7 @@ public function testCategoryUrlWithLeadingSlash() urlResolver(url:"/{$urlPath}") { id - canonical_url + relative_url type } } @@ -312,7 +315,7 @@ public function testCategoryUrlWithLeadingSlash() $response = $this->graphQlQuery($query); $this->assertArrayHasKey('urlResolver', $response); $this->assertEquals($categoryId, $response['urlResolver']['id']); - $this->assertEquals($targetPath, $response['urlResolver']['canonical_url']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']); } @@ -321,13 +324,28 @@ public function testCategoryUrlWithLeadingSlash() */ public function testResolveSlash() { + /** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface */ + $scopeConfigInterface = $this->objectManager->get(ScopeConfigInterface::class); + $homePageIdentifier = $scopeConfigInterface->getValue(PageHelper::XML_PATH_HOME_PAGE, ScopeInterface::SCOPE_STORE); + + /** @var \Magento\Cms\Model\Page $page */ + $page = $this->objectManager->get(\Magento\Cms\Model\Page::class); + $page->load($homePageIdentifier); + $homePageId = $page->getId(); + + /** @var \Magento\CmsUrlRewrite\Model\CmsPageUrlPathGenerator $urlPathGenerator */ + $urlPathGenerator = $this->objectManager->get(\Magento\CmsUrlRewrite\Model\CmsPageUrlPathGenerator::class); + + /** @param \Magento\Cms\Api\Data\PageInterface $page */ + $targetPath = $urlPathGenerator->getCanonicalUrlPath($page); + $query = <<graphQlQuery($query); $this->assertArrayHasKey('urlResolver', $response); - $this->assertEquals(2, $response['urlResolver']['id']); - $this->assertEquals('cms/page/view/page_id/2', $response['urlResolver']['canonical_url']); + $this->assertEquals($homePageId, $response['urlResolver']['id']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals('CMS_PAGE', $response['urlResolver']['type']); } } From 184f90b495ddf0475a34adab7a53250405ba562c Mon Sep 17 00:00:00 2001 From: Pablo Fantini Date: Sun, 16 Sep 2018 00:17:50 -0300 Subject: [PATCH 15/19] GraphQL-80: remove extra lines --- .../Magento/GraphQl/UrlRewrite/UrlResolverTest.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/UrlRewrite/UrlResolverTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/UrlRewrite/UrlResolverTest.php index 4c964265e9f..370121a1dad 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/UrlRewrite/UrlResolverTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/UrlRewrite/UrlResolverTest.php @@ -326,19 +326,18 @@ public function testResolveSlash() { /** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface */ $scopeConfigInterface = $this->objectManager->get(ScopeConfigInterface::class); - $homePageIdentifier = $scopeConfigInterface->getValue(PageHelper::XML_PATH_HOME_PAGE, ScopeInterface::SCOPE_STORE); - + $homePageIdentifier = $scopeConfigInterface->getValue( + PageHelper::XML_PATH_HOME_PAGE, + ScopeInterface::SCOPE_STORE + ); /** @var \Magento\Cms\Model\Page $page */ $page = $this->objectManager->get(\Magento\Cms\Model\Page::class); $page->load($homePageIdentifier); $homePageId = $page->getId(); - /** @var \Magento\CmsUrlRewrite\Model\CmsPageUrlPathGenerator $urlPathGenerator */ $urlPathGenerator = $this->objectManager->get(\Magento\CmsUrlRewrite\Model\CmsPageUrlPathGenerator::class); - /** @param \Magento\Cms\Api\Data\PageInterface $page */ $targetPath = $urlPathGenerator->getCanonicalUrlPath($page); - $query = <<graphQlQuery($query); - $this->assertArrayHasKey('urlResolver', $response); $this->assertEquals($homePageId, $response['urlResolver']['id']); $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); From df0d2ac5cfe4cb3cfc5333b4bfd254333a0a87d5 Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Sun, 16 Sep 2018 09:09:50 +0000 Subject: [PATCH 16/19] GraphQl-44: added schema for format of textarea ui element Signed-off-by: vitaliyboyko --- app/code/Magento/CatalogGraphQl/etc/schema.graphqls | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls index f63c1a96762..bf1116d6c4e 100644 --- a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls @@ -248,8 +248,8 @@ interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\ id: Int @doc(description: "The ID number assigned to the product") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\EntityIdToId") name: String @doc(description: "The product name. Customers use this name to identify the product.") sku: String @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer") - description: String @doc(description: "Detailed information about the product. The value can include simple HTML tags.") @resolver(class: "\\Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductHtmlAttribute") - short_description: String @doc(description: "A short description of the product. Its use depends on the theme.") @resolver(class: "\\Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductHtmlAttribute") + description: ProductHtmlAttribute @doc(description: "Detailed information about the product. The value can include simple HTML tags.") + short_description: ProductHtmlAttribute @doc(description: "A short description of the product. Its use depends on the theme.") special_price: Float @doc(description: "The discounted price of the product") special_from_date: String @doc(description: "The beginning date that a product has a special price") special_to_date: String @doc(description: "The end date that a product has a special price") @@ -551,3 +551,10 @@ type SortFields @doc(description: "SortFields contains a default value for sort default: String @doc(description: "Default value of sort fields") options: [SortField] @doc(description: "Available sort fields") } + +type ProductHtmlAttribute { + content ( + format: String! @doc(description: "The format of content") +): String + @resolver(class: "\\Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductHtmlAttribute") +} From 506c1482629ca2f2a59adc7f99fff272c5a82ad8 Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Sun, 16 Sep 2018 19:01:24 +0000 Subject: [PATCH 17/19] [Revert]GraphQl-44: added schema for format of textarea ui element Will be added in scope of further PR's Signed-off-by: vitaliyboyko --- app/code/Magento/CatalogGraphQl/etc/schema.graphqls | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls index bf1116d6c4e..f63c1a96762 100644 --- a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls @@ -248,8 +248,8 @@ interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\ id: Int @doc(description: "The ID number assigned to the product") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\EntityIdToId") name: String @doc(description: "The product name. Customers use this name to identify the product.") sku: String @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer") - description: ProductHtmlAttribute @doc(description: "Detailed information about the product. The value can include simple HTML tags.") - short_description: ProductHtmlAttribute @doc(description: "A short description of the product. Its use depends on the theme.") + description: String @doc(description: "Detailed information about the product. The value can include simple HTML tags.") @resolver(class: "\\Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductHtmlAttribute") + short_description: String @doc(description: "A short description of the product. Its use depends on the theme.") @resolver(class: "\\Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductHtmlAttribute") special_price: Float @doc(description: "The discounted price of the product") special_from_date: String @doc(description: "The beginning date that a product has a special price") special_to_date: String @doc(description: "The end date that a product has a special price") @@ -551,10 +551,3 @@ type SortFields @doc(description: "SortFields contains a default value for sort default: String @doc(description: "Default value of sort fields") options: [SortField] @doc(description: "Available sort fields") } - -type ProductHtmlAttribute { - content ( - format: String! @doc(description: "The format of content") -): String - @resolver(class: "\\Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductHtmlAttribute") -} From 854264d899b5cc1616d0889c8f67b96385716095 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Mon, 17 Sep 2018 14:43:38 +0300 Subject: [PATCH 18/19] GraphQL-140: Added HTML renderer for description and short description --- .../Resolver/Product/ProductHtmlAttribute.php | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductHtmlAttribute.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductHtmlAttribute.php index 18d15088e66..43fb1355c6b 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductHtmlAttribute.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductHtmlAttribute.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; use Magento\Catalog\Helper\Output as OutputHelper; @@ -20,30 +19,22 @@ */ class ProductHtmlAttribute implements ResolverInterface { - /** - * @var ValueFactory - */ - private $valueFactory; - /** * @var OutputHelper */ private $outputHelper; /** - * @param ValueFactory $valueFactory * @param OutputHelper $outputHelper */ public function __construct( - ValueFactory $valueFactory, OutputHelper $outputHelper ) { - $this->valueFactory = $valueFactory; $this->outputHelper = $outputHelper; } /** - * {@inheritdoc} + * @inheritdoc */ public function resolve( Field $field, @@ -51,22 +42,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']; $fieldName = $field->getName(); $renderedValue = $this->outputHelper->productAttribute($product, $product->getData($fieldName), $fieldName); - $result = function () use ($renderedValue) { - return $renderedValue; - }; - - return $this->valueFactory->create($result); + return $renderedValue; } } From afa216974bf1214ee860e7bb9eeaf0474aee1d4f Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Mon, 17 Sep 2018 20:10:07 +0300 Subject: [PATCH 19/19] GraphQL-169: Quote masked id creation logic moved to create cart resolver --- app/code/Magento/Quote/Model/MaskedQuoteIdToQuoteId.php | 3 +++ app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/app/code/Magento/Quote/Model/MaskedQuoteIdToQuoteId.php b/app/code/Magento/Quote/Model/MaskedQuoteIdToQuoteId.php index f30d98342be..37a8fcd494f 100644 --- a/app/code/Magento/Quote/Model/MaskedQuoteIdToQuoteId.php +++ b/app/code/Magento/Quote/Model/MaskedQuoteIdToQuoteId.php @@ -10,6 +10,9 @@ use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResource; +/** + * MaskedQuoteId to QuoteId resolver + */ class MaskedQuoteIdToQuoteId implements MaskedQuoteIdToQuoteIdInterface { /** diff --git a/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php b/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php index 3c366fcc4ab..2e802f47cfe 100644 --- a/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php +++ b/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php @@ -10,6 +10,9 @@ use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResource; +/** + * QuoteId to MaskedQuoteId resolver + */ class QuoteIdToMaskedQuoteId implements QuoteIdToMaskedQuoteIdInterface { /**