Skip to content

Commit e97301d

Browse files
committed
GraphQL-129: Change resolve to return array, update schema and test
1 parent c0d1b7b commit e97301d

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
use Magento\Framework\GraphQl\Query\ResolverInterface;
1717
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1818

19+
/**
20+
* Customers Token resolver, used for GraphQL request processing.
21+
*/
1922
class GenerateCustomerToken implements ResolverInterface
2023
{
21-
2224
/**
2325
* @var CustomerTokenServiceInterface
2426
*/
@@ -54,7 +56,7 @@ public function resolve(
5456
try {
5557
$token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']);
5658
$result = function () use ($token) {
57-
return !empty($token) ? $token : '';
59+
return !empty($token) ? ['token' => $token] : '';
5860
};
5961
return $this->valueFactory->create($result);
6062
} catch (AuthenticationException $e) {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ type Query {
66
}
77

88
type Mutation {
9-
generateCustomerToken(email: String!, password: String!): String! @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\GenerateCustomerToken") @doc(description:"Retrieve Customer token")
9+
generateCustomerToken(email: String!, password: String!): CustomerToken @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\GenerateCustomerToken") @doc(description:"Retrieve Customer token")
10+
}
11+
12+
type CustomerToken {
13+
token: String @doc(description: "The new customer token")
1014
}
1115

1216
type Customer @doc(description: "Customer defines the customer name and address and other details") {

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
namespace Magento\GraphQl\Customer;
99

1010
use Magento\TestFramework\TestCase\GraphQlAbstract;
11+
use PHPUnit\Framework\TestResult;
1112

13+
/**
14+
* Class GenerateCustomerTokenTest
15+
* @package Magento\GraphQl\Customer
16+
*/
1217
class GenerateCustomerTokenTest extends GraphQlAbstract
1318
{
14-
1519
/**
1620
* Verify customer token with valid credentials
1721
*
@@ -29,13 +33,15 @@ public function testGenerateCustomerValidToken()
2933
generateCustomerToken(
3034
email: "{$userName}"
3135
password: "{$password}"
32-
)
36+
) {
37+
token
38+
}
3339
}
3440
MUTATION;
3541

3642
$response = $this->graphQlQuery($mutation);
3743
$this->assertArrayHasKey('generateCustomerToken', $response);
38-
$this->assertInternalType('string', $response['generateCustomerToken']);
44+
$this->assertInternalType('array', $response['generateCustomerToken']);
3945
}
4046

4147
/**
@@ -54,7 +60,9 @@ public function testGenerateCustomerTokenWithInvalidCredentials()
5460
generateCustomerToken(
5561
email: "{$userName}"
5662
password: "{$password}"
57-
)
63+
) {
64+
token
65+
}
5866
}
5967
MUTATION;
6068

0 commit comments

Comments
 (0)