Skip to content

Commit a56812f

Browse files
ENGCOM-3446: magento2#222 Apply changes from CR for PR 162 #225
- Merge Pull Request magento/graphql-ce#225 from DocSchoko/graphql-ce:222-Apply-CR-fixes-for-pull-request-162 - Merged commits: 1. 3f5bcdd 2. cbd6203 3. 010220c 4. 7f61b6f
2 parents 5f976fa + 7f61b6f commit a56812f

File tree

12 files changed

+33
-25
lines changed

12 files changed

+33
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function execute(int $customerId, array $data): void
7373

7474
if (isset($data['email']) && $customer->getEmail() !== $data['email']) {
7575
if (!isset($data['password']) || empty($data['password'])) {
76-
throw new GraphQlInputException(__('For changing "email" you should provide current "password".'));
76+
throw new GraphQlInputException(__('Provide the current "password" to change "email".'));
7777
}
7878

7979
$this->checkCustomerPassword->execute($data['password'], $customerId);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1818

1919
/**
20-
* @inheritdoc
20+
* Change customer password resolver
2121
*/
2222
class ChangePassword implements ResolverInterface
2323
{
@@ -70,11 +70,11 @@ public function resolve(
7070
array $args = null
7171
) {
7272
if (!isset($args['currentPassword'])) {
73-
throw new GraphQlInputException(__('"currentPassword" value should be specified'));
73+
throw new GraphQlInputException(__('Specify the "currentPassword" value.'));
7474
}
7575

7676
if (!isset($args['newPassword'])) {
77-
throw new GraphQlInputException(__('"newPassword" value should be specified'));
77+
throw new GraphQlInputException(__('Specify the "newPassword" value.'));
7878
}
7979

8080
$currentUserId = $context->getUserId();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public function resolve(
4545
array $args = null
4646
) {
4747
if (!isset($args['email'])) {
48-
throw new GraphQlInputException(__('"email" value should be specified'));
48+
throw new GraphQlInputException(__('Specify the "email" value.'));
4949
}
5050

5151
if (!isset($args['password'])) {
52-
throw new GraphQlInputException(__('"password" value should be specified'));
52+
throw new GraphQlInputException(__('Specify the "password" value.'));
5353
}
5454

5555
try {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ public function resolve(
5555

5656
$this->checkCustomerAccount->execute($currentUserId, $currentUserType);
5757

58-
return $this->customerTokenService->revokeCustomerAccessToken((int)$currentUserId);
58+
return ['result' => $this->customerTokenService->revokeCustomerAccessToken((int)$currentUserId)];
5959
}
6060
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ type Query {
66
}
77

88
type Mutation {
9-
generateCustomerToken(email: String!, password: String!): CustomerToken @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\GenerateCustomerToken") @doc(description:"Retrieve Customer token")
10-
changeCustomerPassword(currentPassword: String!, newPassword: String!): Customer @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\ChangePassword") @doc(description:"Changes password for logged in customer")
11-
updateCustomer (input: UpdateCustomerInput): UpdateCustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomer") @doc(description:"Update customer personal information")
12-
revokeCustomerToken: Boolean @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\RevokeCustomerToken") @doc(description:"Revoke Customer token")
9+
generateCustomerToken(email: String!, password: String!): CustomerToken @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\GenerateCustomerToken") @doc(description:"Retrieve the customer token")
10+
changeCustomerPassword(currentPassword: String!, newPassword: String!): Customer @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\ChangePassword") @doc(description:"Changes the password for the logged-in customer")
11+
updateCustomer (input: UpdateCustomerInput!): UpdateCustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomer") @doc(description:"Update the customer's personal information")
12+
revokeCustomerToken: RevokeCustomerTokenOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\RevokeCustomerToken") @doc(description:"Revoke the customer token")
1313
}
1414

1515
type CustomerToken {
@@ -28,6 +28,10 @@ type UpdateCustomerOutput {
2828
customer: Customer!
2929
}
3030

31+
type RevokeCustomerTokenOutput {
32+
result: Boolean!
33+
}
34+
3135
type Customer @doc(description: "Customer defines the customer name and address and other details") {
3236
created_at: String @doc(description: "Timestamp indicating when the account was created")
3337
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)")

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/AccountInformationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function testUpdateAccountInformationIfCustomerIsLocked()
238238
/**
239239
* @magentoApiDataFixture Magento/Customer/_files/customer.php
240240
* @expectedException \Exception
241-
* @expectedExceptionMessage For changing "email" you should provide current "password".
241+
* @expectedExceptionMessage Provide the current "password" to change "email".
242242
*/
243243
public function testUpdateEmailIfPasswordIsMissed()
244244
{

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/RevokeCustomerTokenTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public function testRevokeCustomerTokenValidCredentials()
2323
{
2424
$query = <<<QUERY
2525
mutation {
26-
revokeCustomerToken
26+
revokeCustomerToken {
27+
result
28+
}
2729
}
2830
QUERY;
2931

@@ -35,7 +37,7 @@ public function testRevokeCustomerTokenValidCredentials()
3537

3638
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
3739
$response = $this->graphQlQuery($query, [], '', $headerMap);
38-
$this->assertTrue($response['revokeCustomerToken']);
40+
$this->assertTrue($response['revokeCustomerToken']['result']);
3941
}
4042

4143
/**
@@ -46,7 +48,9 @@ public function testRevokeCustomerTokenForGuestCustomer()
4648
{
4749
$query = <<<QUERY
4850
mutation {
49-
revokeCustomerToken
51+
revokeCustomerToken {
52+
result
53+
}
5054
}
5155
QUERY;
5256
$this->graphQlQuery($query, [], '');

lib/internal/Magento/Framework/GraphQl/Exception/GraphQlAlreadyExistsException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Framework\Phrase;
1313

1414
/**
15-
* Class GraphQlAlreadyExistsException
15+
* Exception for GraphQL to be thrown when data already exists
1616
*/
1717
class GraphQlAlreadyExistsException extends AlreadyExistsException implements ClientAware
1818
{

lib/internal/Magento/Framework/GraphQl/Exception/GraphQlAuthenticationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Framework\Phrase;
1313

1414
/**
15-
* Class GraphQlAuthenticationException
15+
* Exception for GraphQL to be thrown when authentication fails
1616
*/
1717
class GraphQlAuthenticationException extends AuthenticationException implements ClientAware
1818
{

lib/internal/Magento/Framework/GraphQl/Exception/GraphQlAuthorizationException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\Exception\AuthorizationException;
1212

1313
/**
14-
* Class GraphQlAuthorizationException
14+
* Exception for GraphQL to be thrown when authorization fails
1515
*/
1616
class GraphQlAuthorizationException extends AuthorizationException implements \GraphQL\Error\ClientAware
1717
{
@@ -37,15 +37,15 @@ public function __construct(Phrase $phrase, \Exception $cause = null, $code = 0,
3737
}
3838

3939
/**
40-
* {@inheritDoc}
40+
* @inheritdoc
4141
*/
4242
public function isClientSafe() : bool
4343
{
4444
return $this->isSafe;
4545
}
4646

4747
/**
48-
* {@inheritDoc}
48+
* @inheritdoc
4949
*/
5050
public function getCategory() : string
5151
{

lib/internal/Magento/Framework/GraphQl/Exception/GraphQlInputException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ public function __construct(Phrase $phrase, \Exception $cause = null, $code = 0,
3737
}
3838

3939
/**
40-
* {@inheritDoc}
40+
* @inheritdoc
4141
*/
4242
public function isClientSafe() : bool
4343
{
4444
return $this->isSafe;
4545
}
4646

4747
/**
48-
* {@inheritDoc}
48+
* @inheritdoc
4949
*/
5050
public function getCategory() : string
5151
{

lib/internal/Magento/Framework/GraphQl/Exception/GraphQlNoSuchEntityException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\Phrase;
1212

1313
/**
14-
* Class GraphQlNoSuchEntityException
14+
* Exception for GraphQL to be thrown when entity does not exists
1515
*/
1616
class GraphQlNoSuchEntityException extends NoSuchEntityException implements \GraphQL\Error\ClientAware
1717
{
@@ -37,15 +37,15 @@ public function __construct(Phrase $phrase, \Exception $cause = null, $code = 0,
3737
}
3838

3939
/**
40-
* {@inheritDoc}
40+
* @inheritdoc
4141
*/
4242
public function isClientSafe() : bool
4343
{
4444
return $this->isSafe;
4545
}
4646

4747
/**
48-
* {@inheritDoc}
48+
* @inheritdoc
4949
*/
5050
public function getCategory() : string
5151
{

0 commit comments

Comments
 (0)