Skip to content

Commit 8e3bbd0

Browse files
committed
Merge branch '2.3-develop-mainline' into PULL-12965-FORWARDPORT
2 parents 9e1610e + d7f2541 commit 8e3bbd0

File tree

85 files changed

+2753
-385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2753
-385
lines changed

app/code/Magento/Catalog/view/base/web/template/product/link.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
-->
7-
<a class="product-item-link"
7+
<a if="isAllowed()"
8+
class="product-item-link"
89
attr="href: $row().url"
910
text="label"/>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\GraphQlCatalog\Model\Resolver\Products\Query;
7+
namespace Magento\Framework\GraphQl\Query;
88

99
/**
1010
* Processor or processors to re-format and add additional data outside of the scope of the query's fetch.
@@ -14,8 +14,8 @@ interface PostFetchProcessorInterface
1414
/**
1515
* Process data by formatting and add any necessary additional attributes.
1616
*
17-
* @param array $productData
17+
* @param array $resultData
1818
* @return array
1919
*/
20-
public function process(array $productData);
20+
public function process(array $resultData);
2121
}

app/code/Magento/GraphQl/Controller/GraphQl.php

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
use Magento\Framework\App\Request\Http;
1111
use Magento\Framework\App\RequestInterface;
1212
use Magento\Framework\App\ResponseInterface;
13-
use Magento\Framework\Exception\LocalizedException;
1413
use Magento\Framework\Serialize\SerializerInterface;
1514
use Magento\Framework\Webapi\Response;
1615
use Magento\GraphQl\Model\SchemaGeneratorInterface;
17-
use Magento\Framework\GraphQl\RequestProcessor;
16+
use Magento\Framework\GraphQl\QueryProcessor;
1817
use Magento\Framework\GraphQl\ExceptionFormatter;
1918
use Magento\GraphQl\Model\ResolverContext;
19+
use Magento\Framework\GraphQl\HttpRequestProcessor;
2020

2121
/**
2222
* Front controller for web API GraphQL area.
@@ -39,38 +39,50 @@ class GraphQl implements FrontControllerInterface
3939
private $jsonSerializer;
4040

4141
/**
42-
* @var RequestProcessor
42+
* @var QueryProcessor
4343
*/
44-
private $requestProcessor;
44+
private $queryProcessor;
4545

46-
/** @var ExceptionFormatter */
46+
/**
47+
* @var ExceptionFormatter
48+
*/
4749
private $graphQlError;
4850

49-
/** @var ResolverContext */
51+
/**
52+
* @var ResolverContext
53+
*/
5054
private $context;
5155

56+
/**
57+
* @var HttpRequestProcessor
58+
*/
59+
private $requestProcessor;
60+
5261
/**
5362
* @param Response $response
5463
* @param SchemaGeneratorInterface $schemaGenerator
5564
* @param SerializerInterface $jsonSerializer
56-
* @param RequestProcessor $requestProcessor
65+
* @param QueryProcessor $queryProcessor
5766
* @param ExceptionFormatter $graphQlError
5867
* @param ResolverContext $context
68+
* @param HttpRequestProcessor $requestProcessor
5969
*/
6070
public function __construct(
6171
Response $response,
6272
SchemaGeneratorInterface $schemaGenerator,
6373
SerializerInterface $jsonSerializer,
64-
RequestProcessor $requestProcessor,
74+
QueryProcessor $queryProcessor,
6575
ExceptionFormatter $graphQlError,
66-
ResolverContext $context
76+
ResolverContext $context,
77+
HttpRequestProcessor $requestProcessor
6778
) {
6879
$this->response = $response;
6980
$this->schemaGenerator = $schemaGenerator;
7081
$this->jsonSerializer = $jsonSerializer;
71-
$this->requestProcessor = $requestProcessor;
82+
$this->queryProcessor = $queryProcessor;
7283
$this->graphQlError = $graphQlError;
7384
$this->context = $context;
85+
$this->requestProcessor = $requestProcessor;
7486
}
7587

7688
/**
@@ -82,17 +94,11 @@ public function __construct(
8294
public function dispatch(RequestInterface $request)
8395
{
8496
try {
85-
/** @var $request Http */
86-
if ($request->getHeader('Content-Type')
87-
&& strpos($request->getHeader('Content-Type'), 'application/json') !== false
88-
) {
89-
$content = $request->getContent();
90-
$data = $this->jsonSerializer->unserialize($content);
91-
} else {
92-
throw new LocalizedException(__('Request content type must be application/json'));
93-
}
97+
/** @var Http $request */
98+
$this->requestProcessor->processHeaders($request);
99+
$data = $this->jsonSerializer->unserialize($request->getContent());
94100
$schema = $this->schemaGenerator->generate();
95-
$result = $this->requestProcessor->process(
101+
$result = $this->queryProcessor->process(
96102
$schema,
97103
isset($data['query']) ? $data['query'] : '',
98104
null,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GraphQl\Controller\HttpHeaderProcessor;
8+
9+
use Magento\Framework\GraphQl\HttpHeaderProcessorInterface;
10+
use Magento\Framework\Exception\LocalizedException;
11+
12+
/**
13+
* Processes the "Content-Type" header entry
14+
*/
15+
class ContentTypeProcessor implements HttpHeaderProcessorInterface
16+
{
17+
/**
18+
* Handle the mandatory application/json header
19+
*
20+
* {@inheritDoc}
21+
* @throws LocalizedException
22+
*/
23+
public function processHeaderValue($headerValue)
24+
{
25+
if (!$headerValue || strpos($headerValue, 'application/json') === false) {
26+
throw new LocalizedException(
27+
new \Magento\Framework\Phrase('Request content type must be application/json')
28+
);
29+
}
30+
}
31+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GraphQl\Controller\HttpHeaderProcessor;
8+
9+
use Magento\Framework\GraphQl\HttpHeaderProcessorInterface;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
13+
14+
/**
15+
* Process the "Store" header entry
16+
*/
17+
class StoreProcessor implements HttpHeaderProcessorInterface
18+
{
19+
/**
20+
* @var StoreManagerInterface
21+
*/
22+
private $storeManager;
23+
24+
/**
25+
* StoreProcessor constructor.
26+
* @param StoreManagerInterface $storeManager
27+
*/
28+
public function __construct(StoreManagerInterface $storeManager)
29+
{
30+
$this->storeManager = $storeManager;
31+
}
32+
33+
/**
34+
* Handle the value of the store and set the scope
35+
*
36+
* {@inheritDoc}
37+
* @throws NoSuchEntityException
38+
*/
39+
public function processHeaderValue($headerValue)
40+
{
41+
if ($headerValue) {
42+
$storeCode = ltrim(rtrim($headerValue));
43+
$stores = $this->storeManager->getStores(false, true);
44+
if (isset($stores[$storeCode])) {
45+
$this->storeManager->setCurrentStore($storeCode);
46+
} elseif (strtolower($storeCode) !== 'default') {
47+
throw new GraphQlInputException(
48+
new \Magento\Framework\Phrase('Store code %1 does not exist', [$storeCode])
49+
);
50+
}
51+
}
52+
}
53+
}

app/code/Magento/GraphQl/Model/EntityAttributeList.php

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,106 @@
77
namespace Magento\GraphQl\Model;
88

99
use Magento\Eav\Api\AttributeManagementInterface;
10-
use Magento\Eav\Setup\EavSetupFactory;
11-
use Magento\Eav\Setup\EavSetup;
10+
use Magento\Eav\Api\AttributeSetRepositoryInterface;
11+
use Magento\Eav\Api\Data\AttributeInterface;
12+
use Magento\Framework\Api\FilterBuilder;
13+
use Magento\Framework\Api\MetadataServiceInterface;
14+
use Magento\Framework\Api\SearchCriteriaBuilder;
15+
use Magento\Framework\Exception\NoSuchEntityException;
16+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1217

18+
/**
19+
* Iterate through all attribute sets to retrieve attributes for any given entity type
20+
*/
1321
class EntityAttributeList
1422
{
1523
/**
1624
* @var AttributeManagementInterface
1725
*/
18-
private $management;
26+
private $attributeManagement;
1927

2028
/**
21-
* @var EavSetupFactory
29+
* @var AttributeSetRepositoryInterface
2230
*/
23-
private $eavSetupFactory;
31+
private $attributeSetRepository;
2432

2533
/**
26-
* @var EavSetup
34+
* @var SearchCriteriaBuilder
2735
*/
28-
private $eavSetup;
36+
private $searchCriteriaBuilder;
2937

3038
/**
31-
* @param AttributeManagementInterface $management
32-
* @param EavSetupFactory $eavSetupFactory
39+
* @var FilterBuilder
40+
*/
41+
private $filterBuilder;
42+
43+
/**
44+
* @param AttributeManagementInterface $attributeManagement
45+
* @param AttributeSetRepositoryInterface $attributeSetRepository
46+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
47+
* @param FilterBuilder $filterBuilder
3348
*/
3449
public function __construct(
35-
AttributeManagementInterface $management,
36-
EavSetupFactory $eavSetupFactory
50+
AttributeManagementInterface $attributeManagement,
51+
AttributeSetRepositoryInterface $attributeSetRepository,
52+
SearchCriteriaBuilder $searchCriteriaBuilder,
53+
FilterBuilder $filterBuilder
3754
) {
38-
$this->management = $management;
39-
$this->eavSetupFactory = $eavSetupFactory;
40-
$this->eavSetup = $this->eavSetupFactory->create();
55+
$this->attributeManagement = $attributeManagement;
56+
$this->attributeSetRepository = $attributeSetRepository;
57+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
58+
$this->filterBuilder = $filterBuilder;
4159
}
4260

43-
public function getDefaultEntityAttributes(string $entityCode)
61+
/**
62+
* Retrieve all EAV and custom attribute codes from all attribute sets for given entity code.
63+
*
64+
* Returned in the format [$attributeCode => $isSortable] with $isSortable being a boolean value where an attribute
65+
* can be sorted with in a search criteria expression. The metadata service parameter is only required if type has
66+
* custom attributes.
67+
*
68+
* @param string $entityCode
69+
* @param MetadataServiceInterface $metadataService
70+
* @return boolean[]
71+
* @throws GraphQlInputException
72+
*/
73+
public function getDefaultEntityAttributes(string $entityCode, MetadataServiceInterface $metadataService = null)
4474
{
45-
$defaultAttributeSetId = $this->eavSetup->getDefaultAttributeSetId($entityCode);
46-
return $this->management->getAttributes($entityCode, $defaultAttributeSetId);
75+
$this->searchCriteriaBuilder->addFilters(
76+
[
77+
$this->filterBuilder
78+
->setField('entity_type_code')
79+
->setValue($entityCode)
80+
->setConditionType('eq')
81+
->create(),
82+
]
83+
);
84+
$attributeSetList = $this->attributeSetRepository->getList($this->searchCriteriaBuilder->create())->getItems();
85+
$attributes = [];
86+
foreach ($attributeSetList as $attributeSet) {
87+
try {
88+
$attributes = array_merge(
89+
$attributes,
90+
$this->attributeManagement->getAttributes($entityCode, $attributeSet->getAttributeSetId())
91+
);
92+
} catch (NoSuchEntityException $exception) {
93+
throw new GraphQlInputException(__('Entity code %1 does not exist.', [$entityCode]));
94+
}
95+
}
96+
$attributeCodes = [];
97+
$metadata = $metadataService ? $metadataService->getCustomAttributesMetadata() : [];
98+
foreach ($metadata as $customAttribute) {
99+
if (!array_key_exists($customAttribute->getAttributeCode(), $attributeCodes)) {
100+
$attributeCodes[$customAttribute->getAttributeCode()] = false;
101+
}
102+
}
103+
/** @var AttributeInterface $attribute */
104+
foreach ($attributes as $attribute) {
105+
if (!array_key_exists($attribute->getAttributeCode(), $attributeCodes)) {
106+
$attributeCodes[$attribute->getAttributeCode()]
107+
= ((! $attribute->getIsUserDefined()) && !is_array($attribute));
108+
}
109+
}
110+
return $attributeCodes;
47111
}
48112
}

app/code/Magento/GraphQl/Model/SchemaGenerator.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,6 @@ public function generate()
8484
'fields' => $schemaConfig['fields'],
8585
'resolveField' => function ($value, $args, $context, ResolveInfo $info) {
8686
$fieldName = $info->fieldName;
87-
$fieldNodes = $info->fieldNodes;
88-
$selections = [];
89-
// foreach ($fieldNodes as $fieldNode) {
90-
// foreach ($fieldNode->selectionSet->selections as $field) {
91-
// $name = $field->name;
92-
// if (isset($field->selectionSet)) {
93-
// $selections[$name] = $this->getFields;
94-
// }
95-
// foreach ($field->selectionSet->selections as $selection) {
96-
// $selections[$name] = $selection->name;
97-
// }
98-
// }
99-
// }
10087
$resolver = $this->resolverFactory->create($fieldName);
10188

10289
$fieldArguments = [];

app/code/Magento/GraphQl/Model/Type/Handler/Pool/Complex.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ class Complex
2626
*/
2727
private $typeHandlerFactory;
2828

29+
/**
30+
* @param HandlerConfig $typeConfig
31+
* @param HandlerFactory $typeHandlerFactory
32+
*/
33+
public function __construct(HandlerConfig $typeConfig, HandlerFactory $typeHandlerFactory)
34+
{
35+
$this->typeConfig = $typeConfig;
36+
$this->typeHandlerFactory = $typeHandlerFactory;
37+
}
38+
2939
/**
3040
* Retrieve type's configuration based off name
3141
*

app/code/Magento/GraphQl/Model/Type/ServiceContract/TypeGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
/**
1919
* Translate web API service contract layer from array-style schema to GraphQL types
20+
*
21+
* @api
2022
*/
2123
class TypeGenerator
2224
{

app/code/Magento/GraphQl/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"require": {
77
"php": "7.0.2|7.0.4|~7.0.6|~7.1.0",
88
"magento/module-authorization": "100.3.*",
9+
"magento/module-store": "100.3.*",
910
"magento/module-webapi": "100.3.*",
1011
"magento/module-eav": "100.3.*",
1112
"magento/framework": "100.3.*"

0 commit comments

Comments
 (0)