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

Commit ba532b3

Browse files
author
Magento CICD
authored
merge magento/2.3-develop into magento-honey-badgers/2.3.0-release-merge
2 parents 6fd18bf + 18dcf17 commit ba532b3

File tree

28 files changed

+748
-180
lines changed

28 files changed

+748
-180
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\CatalogGraphQl\Model\Resolver;
99

10+
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\ExtractDataFromCategoryTree;
1011
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1112
use Magento\Framework\GraphQl\Config\Element\Field;
1213
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
@@ -27,16 +28,26 @@ class CategoryTree implements ResolverInterface
2728
*/
2829
private $categoryTree;
2930

31+
/**
32+
* @var ExtractDataFromCategoryTree
33+
*/
34+
private $extractDataFromCategoryTree;
35+
3036
/**
3137
* @param \Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree $categoryTree
38+
* @param ExtractDataFromCategoryTree $extractDataFromCategoryTree
3239
*/
3340
public function __construct(
34-
\Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree $categoryTree
41+
\Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree $categoryTree,
42+
ExtractDataFromCategoryTree $extractDataFromCategoryTree
3543
) {
3644
$this->categoryTree = $categoryTree;
45+
$this->extractDataFromCategoryTree = $extractDataFromCategoryTree;
3746
}
3847

3948
/**
49+
* Get category id
50+
*
4051
* @param array $args
4152
* @return int
4253
* @throws GraphQlInputException
@@ -62,7 +73,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6273
$rootCategoryId = $this->getCategoryId($args);
6374
$categoriesTree = $this->categoryTree->getTree($info, $rootCategoryId);
6475
if (!empty($categoriesTree)) {
65-
return current($categoriesTree);
76+
$result = $this->extractDataFromCategoryTree->execute($categoriesTree);
77+
return current($result);
6678
} else {
6779
return null;
6880
}

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
use GraphQL\Language\AST\FieldNode;
1111
use Magento\CatalogGraphQl\Model\Category\DepthCalculator;
12-
use Magento\CatalogGraphQl\Model\Category\Hydrator;
1312
use Magento\CatalogGraphQl\Model\Category\LevelCalculator;
1413
use Magento\Framework\EntityManager\MetadataPool;
1514
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1615
use Magento\Catalog\Api\Data\CategoryInterface;
1716
use Magento\Catalog\Model\ResourceModel\Category\Collection;
1817
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
1918
use Magento\CatalogGraphQl\Model\AttributesJoiner;
19+
use Magento\Catalog\Model\Category;
2020

2121
/**
2222
* Category tree data provider
@@ -53,87 +53,64 @@ class CategoryTree
5353
*/
5454
private $metadata;
5555

56-
/**
57-
* @var Hydrator
58-
*/
59-
private $hydrator;
60-
6156
/**
6257
* @param CollectionFactory $collectionFactory
6358
* @param AttributesJoiner $attributesJoiner
6459
* @param DepthCalculator $depthCalculator
6560
* @param LevelCalculator $levelCalculator
6661
* @param MetadataPool $metadata
67-
* @param Hydrator $hydrator
6862
*/
6963
public function __construct(
7064
CollectionFactory $collectionFactory,
7165
AttributesJoiner $attributesJoiner,
7266
DepthCalculator $depthCalculator,
7367
LevelCalculator $levelCalculator,
74-
MetadataPool $metadata,
75-
Hydrator $hydrator
68+
MetadataPool $metadata
7669
) {
7770
$this->collectionFactory = $collectionFactory;
7871
$this->attributesJoiner = $attributesJoiner;
7972
$this->depthCalculator = $depthCalculator;
8073
$this->levelCalculator = $levelCalculator;
8174
$this->metadata = $metadata;
82-
$this->hydrator = $hydrator;
8375
}
8476

8577
/**
8678
* Returns categories tree starting from parent $rootCategoryId
8779
*
8880
* @param ResolveInfo $resolveInfo
8981
* @param int $rootCategoryId
90-
* @return array
82+
* @return \Iterator
9183
*/
92-
public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId) : array
84+
public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterator
9385
{
9486
$categoryQuery = $resolveInfo->fieldNodes[0];
9587
$collection = $this->collectionFactory->create();
9688
$this->joinAttributesRecursively($collection, $categoryQuery);
9789
$depth = $this->depthCalculator->calculate($categoryQuery);
9890
$level = $this->levelCalculator->calculate($rootCategoryId);
91+
92+
// If root category is being filter, we've to remove first slash
93+
if ($rootCategoryId == Category::TREE_ROOT_ID) {
94+
$regExpPathFilter = sprintf('.*%s/[/0-9]*$', $rootCategoryId);
95+
} else {
96+
$regExpPathFilter = sprintf('.*/%s/[/0-9]*$', $rootCategoryId);
97+
}
98+
9999
//Search for desired part of category tree
100-
$collection->addPathFilter(sprintf('.*/%s/[/0-9]*$', $rootCategoryId));
100+
$collection->addPathFilter($regExpPathFilter);
101+
101102
$collection->addFieldToFilter('level', ['gt' => $level]);
102103
$collection->addFieldToFilter('level', ['lteq' => $level + $depth - self::DEPTH_OFFSET]);
103104
$collection->setOrder('level');
104105
$collection->getSelect()->orWhere(
105106
$this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() . ' = ?',
106107
$rootCategoryId
107108
);
108-
return $this->processTree($collection->getIterator());
109-
}
110-
111-
/**
112-
* Iterates through category tree
113-
*
114-
* @param \Iterator $iterator
115-
* @return array
116-
*/
117-
private function processTree(\Iterator $iterator) : array
118-
{
119-
$tree = [];
120-
while ($iterator->valid()) {
121-
/** @var CategoryInterface $category */
122-
$category = $iterator->current();
123-
$iterator->next();
124-
$nextCategory = $iterator->current();
125-
$tree[$category->getId()] = $this->hydrator->hydrateCategory($category);
126-
$tree[$category->getId()]['model'] = $category;
127-
if ($nextCategory && (int) $nextCategory->getLevel() !== (int) $category->getLevel()) {
128-
$tree[$category->getId()]['children'] = $this->processTree($iterator);
129-
}
130-
}
131-
132-
return $tree;
109+
return $collection->getIterator();
133110
}
134111

135112
/**
136-
* Joins EAV attributes recursively
113+
* Join attributes recursively
137114
*
138115
* @param Collection $collection
139116
* @param FieldNode $fieldNode
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider;
9+
10+
use Magento\CatalogGraphQl\Model\Category\Hydrator;
11+
use Magento\Catalog\Api\Data\CategoryInterface;
12+
13+
/**
14+
* Extract data from category tree
15+
*/
16+
class ExtractDataFromCategoryTree
17+
{
18+
/**
19+
* @var Hydrator
20+
*/
21+
private $categoryHydrator;
22+
23+
/**
24+
* @param Hydrator $categoryHydrator
25+
*/
26+
public function __construct(
27+
Hydrator $categoryHydrator
28+
) {
29+
$this->categoryHydrator = $categoryHydrator;
30+
}
31+
32+
/**
33+
* Extract data from category tree
34+
*
35+
* @param \Iterator $iterator
36+
* @return array
37+
*/
38+
public function execute(\Iterator $iterator): array
39+
{
40+
$tree = [];
41+
while ($iterator->valid()) {
42+
/** @var CategoryInterface $category */
43+
$category = $iterator->current();
44+
$iterator->next();
45+
$nextCategory = $iterator->current();
46+
$tree[$category->getId()] = $this->categoryHydrator->hydrateCategory($category);
47+
$tree[$category->getId()]['model'] = $category;
48+
if ($nextCategory && (int) $nextCategory->getLevel() !== (int) $category->getLevel()) {
49+
$tree[$category->getId()]['children'] = $this->execute($iterator);
50+
}
51+
}
52+
53+
return $tree;
54+
}
55+
}

app/code/Magento/CatalogUrlRewriteGraphQl/etc/module.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_CatalogUrlRewriteGraphQl" />
9+
<module name="Magento_CatalogUrlRewriteGraphQl" >
10+
<sequence>
11+
<module name="Magento_UrlRewriteGraphQl"/>
12+
<module name="Magento_CatalogGraphQl"/>
13+
</sequence>
14+
</module>
1015
</config>

app/code/Magento/CatalogUrlRewriteGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
interface ProductInterface {
55
url_key: String @doc(description: "The part of the URL that identifies the product")
66
url_path: String @doc(description: "The part of the URL that precedes the url_key")
7+
url_rewrites: [UrlRewrite] @doc(description: "URL rewrites list") @resolver(class: "Magento\\UrlRewriteGraphQl\\Model\\Resolver\\UrlRewrite")
78
}
89

910
input ProductFilterInput {

app/code/Magento/CmsGraphQl/composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"magento/module-cms": "*",
99
"magento/module-widget": "*"
1010
},
11+
"suggest": {
12+
"magento/module-graph-ql": "*",
13+
"magento/module-store-graph-ql": "*"
14+
},
1115
"license": [
1216
"OSL-3.0",
1317
"AFL-3.0"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
10+
<arguments>
11+
<argument name="extendedConfigData" xsi:type="array">
12+
<item name="front" xsi:type="string">web/default/front</item>
13+
<item name="cms_home_page" xsi:type="string">web/default/cms_home_page</item>
14+
<item name="no_route" xsi:type="string">web/default/no_route</item>
15+
<item name="cms_no_route" xsi:type="string">web/default/cms_no_route</item>
16+
<item name="cms_no_cookies" xsi:type="string">web/default/cms_no_cookies</item>
17+
<item name="show_cms_breadcrumbs" xsi:type="string">web/default/show_cms_breadcrumbs</item>
18+
</argument>
19+
</arguments>
20+
</type>
21+
</config>

app/code/Magento/CmsGraphQl/etc/schema.graphqls

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Copyright © Magento, Inc. All rights reserved.
22
# See COPYING.txt for license details.
3+
type StoreConfig @doc(description: "The type contains information about a store config") {
4+
front : String @doc(description: "Default Web URL")
5+
cms_home_page : String @doc(description: "CMS Home Page")
6+
no_route : String @doc(description: "Default No-route URL")
7+
cms_no_route : String @doc(description: "CMS No Route Page")
8+
cms_no_cookies : String @doc(description: "CMS No Cookies Page")
9+
show_cms_breadcrumbs : Int @doc(description: "Show Breadcrumbs for CMS Pages")
10+
}
11+
312

413
type Query {
514
cmsPage (
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CustomerGraphQl\Model\Resolver\Customer\Account;
9+
10+
use Magento\Authorization\Model\UserContextInterface;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\Integration\Api\CustomerTokenServiceInterface;
16+
17+
/**
18+
* Customers Revoke Token resolver, used for GraphQL request processing.
19+
*/
20+
class RevokeCustomerToken implements ResolverInterface
21+
{
22+
/**
23+
* @var UserContextInterface
24+
*/
25+
private $userContext;
26+
27+
/**
28+
* @var CustomerTokenServiceInterface
29+
*/
30+
private $customerTokenService;
31+
32+
/**
33+
* @param UserContextInterface $userContext
34+
* @param CustomerTokenServiceInterface $customerTokenService
35+
*/
36+
public function __construct(
37+
UserContextInterface $userContext,
38+
CustomerTokenServiceInterface $customerTokenService
39+
) {
40+
$this->userContext = $userContext;
41+
$this->customerTokenService = $customerTokenService;
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
public function resolve(
48+
Field $field,
49+
$context,
50+
ResolveInfo $info,
51+
array $value = null,
52+
array $args = null
53+
) {
54+
$customerId = (int)$this->userContext->getUserId();
55+
56+
if ($customerId === 0) {
57+
throw new GraphQlAuthorizationException(
58+
__(
59+
'Current customer does not have access to the resource "%1"',
60+
[\Magento\Customer\Model\Customer::ENTITY]
61+
)
62+
);
63+
}
64+
65+
return $this->customerTokenService->revokeCustomerAccessToken($customerId);
66+
}
67+
}

app/code/Magento/CustomerGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type Query {
88
type Mutation {
99
generateCustomerToken(email: String!, password: String!): CustomerToken @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\GenerateCustomerToken") @doc(description:"Retrieve Customer token")
1010
changeCustomerPassword(currentPassword: String!, newPassword: String!): Customer @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\ChangePassword") @doc(description:"Changes password for logged in customer")
11+
revokeCustomerToken: Boolean @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\RevokeCustomerToken") @doc(description:"Revoke Customer token")
1112
}
1213

1314
type CustomerToken {

0 commit comments

Comments
 (0)