Skip to content

Commit 8f5cd5d

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents 5261d4e + 8a20a76 commit 8f5cd5d

File tree

29 files changed

+510
-142
lines changed

29 files changed

+510
-142
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The Magento 2 development team or community maintainers will review all issues a
1111
During the review we might require clarifications from the contributor.
1212
If there is no response from the contributor within two weeks, the pull request will be closed.
1313

14-
For more detialed information on contribution please read our [beginners guide](https://github.com/magento/magento2/wiki/Getting-Started).
14+
For more detailed information on contribution please read our [beginners guide](https://github.com/magento/magento2/wiki/Getting-Started).
1515

1616
## Contribution requirements
1717

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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\Context;
9+
10+
use Magento\Authorization\Model\UserContextInterface;
11+
use Magento\GraphQl\Model\Query\ContextParametersInterface;
12+
use Magento\GraphQl\Model\Query\ContextParametersProcessorInterface;
13+
14+
/**
15+
* @inheritdoc
16+
*/
17+
class AddUserInfoToContext implements ContextParametersProcessorInterface
18+
{
19+
/**
20+
* @var UserContextInterface
21+
*/
22+
private $userContext;
23+
24+
/**
25+
* @param UserContextInterface $userContext
26+
*/
27+
public function __construct(
28+
UserContextInterface $userContext
29+
) {
30+
$this->userContext = $userContext;
31+
}
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
public function execute(ContextParametersInterface $contextParameters): ContextParametersInterface
37+
{
38+
$currentUserId = $this->userContext->getUserId();
39+
if (null !== $currentUserId) {
40+
$currentUserId = (int)$currentUserId;
41+
}
42+
43+
$currentUserType = $this->userContext->getUserType();
44+
if (null !== $currentUserType) {
45+
$currentUserType = (int)$currentUserType;
46+
}
47+
48+
$contextParameters->setUserId($currentUserId);
49+
$contextParameters->setUserType($currentUserType);
50+
return $contextParameters;
51+
}
52+
}

app/code/Magento/CustomerGraphQl/Model/Customer/SaveCustomer.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Framework\Exception\AlreadyExistsException;
1212
use Magento\Framework\Exception\LocalizedException;
1313
use Magento\Framework\GraphQl\Exception\GraphQlAlreadyExistsException;
14-
use Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException;
1514
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1615
use Magento\Customer\Api\Data\CustomerInterface;
1716

@@ -39,7 +38,6 @@ public function __construct(
3938
*
4039
* @param CustomerInterface $customer
4140
* @throws GraphQlAlreadyExistsException
42-
* @throws GraphQlAuthenticationException
4341
* @throws GraphQlInputException
4442
*/
4543
public function execute(CustomerInterface $customer): void

app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php

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

88
namespace Magento\CustomerGraphQl\Model\Resolver;
99

10-
use Magento\Authorization\Model\UserContextInterface;
1110
use Magento\CustomerGraphQl\Model\Customer\CreateCustomerAccount;
1211
use Magento\CustomerGraphQl\Model\Customer\ExtractCustomerData;
1312
use Magento\Framework\GraphQl\Config\Element\Field;
@@ -58,9 +57,6 @@ public function resolve(
5857

5958
$customer = $this->createCustomerAccount->execute($args['input']);
6059

61-
$context->setUserId((int)$customer->getId());
62-
$context->setUserType(UserContextInterface::USER_TYPE_CUSTOMER);
63-
6460
$data = $this->extractCustomerData->execute($customer);
6561
return ['customer' => $data];
6662
}

app/code/Magento/CustomerGraphQl/Model/Resolver/IsSubscribed.php

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

88
namespace Magento\CustomerGraphQl\Model\Resolver;
99

10-
use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
10+
use Magento\Framework\Exception\LocalizedException;
1111
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1212
use Magento\Framework\GraphQl\Config\Element\Field;
1313
use Magento\Framework\GraphQl\Query\ResolverInterface;
@@ -18,25 +18,17 @@
1818
*/
1919
class IsSubscribed implements ResolverInterface
2020
{
21-
/**
22-
* @var GetCustomer
23-
*/
24-
private $getCustomer;
25-
2621
/**
2722
* @var SubscriberFactory
2823
*/
2924
private $subscriberFactory;
3025

3126
/**
32-
* @param GetCustomer $getCustomer
3327
* @param SubscriberFactory $subscriberFactory
3428
*/
3529
public function __construct(
36-
GetCustomer $getCustomer,
3730
SubscriberFactory $subscriberFactory
3831
) {
39-
$this->getCustomer = $getCustomer;
4032
$this->subscriberFactory = $subscriberFactory;
4133
}
4234

@@ -50,7 +42,11 @@ public function resolve(
5042
array $value = null,
5143
array $args = null
5244
) {
53-
$customer = $this->getCustomer->execute($context);
45+
if (!isset($value['model'])) {
46+
throw new LocalizedException(__('"model" value should be specified'));
47+
}
48+
/** @var Customer $customer */
49+
$customer = $value['model'];
5450

5551
$status = $this->subscriberFactory->create()->loadByCustomerId((int)$customer->getId())->isSubscribed();
5652
return (bool)$status;

app/code/Magento/CustomerGraphQl/composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
"type": "magento2-module",
55
"require": {
66
"php": "~7.1.3||~7.2.0",
7-
"magento/module-customer": "*",
87
"magento/module-authorization": "*",
8+
"magento/module-customer": "*",
99
"magento/module-eav": "*",
10+
"magento/module-graph-ql": "*",
1011
"magento/module-newsletter": "*",
1112
"magento/module-integration": "*",
1213
"magento/module-store": "*",
1314
"magento/framework": "*"
1415
},
15-
"suggest": {
16-
"magento/module-graph-ql": "*"
17-
},
1816
"license": [
1917
"OSL-3.0",
2018
"AFL-3.0"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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:Api/etc/extension_attributes.xsd">
9+
<extension_attributes for="Magento\GraphQl\Model\Query\ContextInterface">
10+
<attribute code="customer" type="Magento\Customer\Api\Data\CustomerInterface"/>
11+
</extension_attributes>
12+
</config>

app/code/Magento/CustomerGraphQl/etc/graphql/di.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@
1313
</argument>
1414
</arguments>
1515
</type>
16-
</config>
16+
<type name="Magento\GraphQl\Model\Query\ContextFactory">
17+
<arguments>
18+
<argument name="contextParametersProcessors" xsi:type="array">
19+
<item name="add_user_info_to_context" xsi:type="object">Magento\CustomerGraphQl\Model\Context\AddUserInfoToContext</item>
20+
</argument>
21+
</arguments>
22+
</type>
23+
</config>

app/code/Magento/Deploy/Console/ConsoleLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private function renderProgressBar(OutputInterface $output, array $process)
271271
return "{$title}{$titlePad}"
272272
. "{$count}{$countPad}"
273273
. "{$this->renderBar($output, $process)} "
274-
. "{$percent}%{$percentPad}"
274+
. "{$percent}{$percentPad}"
275275
. "{$process['elapsed']} ";
276276
}
277277

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Magento\Framework\GraphQl\Query\Fields as QueryFields;
2222
use Magento\Framework\Controller\Result\JsonFactory;
2323
use Magento\Framework\App\ObjectManager;
24+
use Magento\GraphQl\Model\Query\ContextFactoryInterface;
2425

2526
/**
2627
* Front controller for web API GraphQL area.
@@ -58,6 +59,7 @@ class GraphQl implements FrontControllerInterface
5859

5960
/**
6061
* @var ContextInterface
62+
* @deprecated $contextFactory is used for creating Context object
6163
*/
6264
private $resolverContext;
6365

@@ -81,17 +83,23 @@ class GraphQl implements FrontControllerInterface
8183
*/
8284
private $httpResponse;
8385

86+
/**
87+
* @var ContextFactoryInterface
88+
*/
89+
private $contextFactory;
90+
8491
/**
8592
* @param Response $response
8693
* @param SchemaGeneratorInterface $schemaGenerator
8794
* @param SerializerInterface $jsonSerializer
8895
* @param QueryProcessor $queryProcessor
8996
* @param ExceptionFormatter $graphQlError
90-
* @param ContextInterface $resolverContext
97+
* @param ContextInterface $resolverContext Deprecated. $contextFactory is used for creating Context object.
9198
* @param HttpRequestProcessor $requestProcessor
9299
* @param QueryFields $queryFields
93100
* @param JsonFactory|null $jsonFactory
94101
* @param HttpResponse|null $httpResponse
102+
* @param ContextFactoryInterface $contextFactory
95103
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
96104
*/
97105
public function __construct(
@@ -104,7 +112,8 @@ public function __construct(
104112
HttpRequestProcessor $requestProcessor,
105113
QueryFields $queryFields,
106114
JsonFactory $jsonFactory = null,
107-
HttpResponse $httpResponse = null
115+
HttpResponse $httpResponse = null,
116+
ContextFactoryInterface $contextFactory = null
108117
) {
109118
$this->response = $response;
110119
$this->schemaGenerator = $schemaGenerator;
@@ -116,6 +125,7 @@ public function __construct(
116125
$this->queryFields = $queryFields;
117126
$this->jsonFactory = $jsonFactory ?: ObjectManager::getInstance()->get(JsonFactory::class);
118127
$this->httpResponse = $httpResponse ?: ObjectManager::getInstance()->get(HttpResponse::class);
128+
$this->contextFactory = $contextFactory ?: ObjectManager::getInstance()->get(ContextFactoryInterface::class);
119129
}
120130

121131
/**
@@ -144,7 +154,7 @@ public function dispatch(RequestInterface $request) : ResponseInterface
144154
$result = $this->queryProcessor->process(
145155
$schema,
146156
$query,
147-
$this->resolverContext,
157+
$this->contextFactory->create(),
148158
$data['variables'] ?? []
149159
);
150160
} catch (\Exception $error) {

0 commit comments

Comments
 (0)