This repository has been archived by the owner on May 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3183 from magento-engcom/graphql-develop-prs
[EngCom] Public Pull Requests - GraphQL
- Loading branch information
Showing
13 changed files
with
340 additions
and
33 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductHtmlAttribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Product; | ||
|
||
use Magento\Catalog\Model\Product; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
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; | ||
|
||
/** | ||
* Resolve rendered content for attributes where HTML content is allowed | ||
*/ | ||
class ProductHtmlAttribute implements ResolverInterface | ||
{ | ||
/** | ||
* @var OutputHelper | ||
*/ | ||
private $outputHelper; | ||
|
||
/** | ||
* @param OutputHelper $outputHelper | ||
*/ | ||
public function __construct( | ||
OutputHelper $outputHelper | ||
) { | ||
$this->outputHelper = $outputHelper; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
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 $product Product */ | ||
$product = $value['model']; | ||
$fieldName = $field->getName(); | ||
$renderedValue = $this->outputHelper->productAttribute($product, $product->getData($fieldName), $fieldName); | ||
return $renderedValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CustomerGraphQl\Model\Resolver\Customer\Account; | ||
|
||
use Magento\Framework\Exception\AuthenticationException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; | ||
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. | ||
*/ | ||
class GenerateCustomerToken implements ResolverInterface | ||
{ | ||
/** | ||
* @var CustomerTokenServiceInterface | ||
*/ | ||
private $customerTokenService; | ||
|
||
/** | ||
* @param CustomerTokenServiceInterface $customerTokenService | ||
*/ | ||
public function __construct( | ||
CustomerTokenServiceInterface $customerTokenService | ||
) { | ||
$this->customerTokenService = $customerTokenService; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
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) { | ||
throw new GraphQlAuthorizationException( | ||
__($e->getMessage()) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...api-functional/testsuite/Magento/GraphQl/Catalog/ProductWithDescriptionDirectivesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Catalog; | ||
|
||
use Magento\Catalog\Api\Data\ProductInterface; | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\TestFramework\ObjectManager; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
/** | ||
* Test for checking that product fields with directives allowed are rendered correctly | ||
*/ | ||
class ProductWithDescriptionDirectivesTest extends GraphQlAbstract | ||
{ | ||
/** | ||
* @var \Magento\TestFramework\ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
protected function setUp() | ||
{ | ||
$this->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 = <<<QUERY | ||
{ | ||
products(filter: {sku: {eq: "{$productSku}"}}) { | ||
items { | ||
description | ||
short_description | ||
} | ||
} | ||
} | ||
QUERY; | ||
$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']); | ||
} | ||
} |
Oops, something went wrong.