Skip to content

Commit ea9b2a8

Browse files
committed
GraphQL-129: Change generate token schema and add graphql exception
1 parent 527e4fe commit ea9b2a8

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ public function resolve(
5959
array $value = null,
6060
array $args = null
6161
): Value {
62-
63-
$token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']);
64-
//TODO: exception
65-
$result = function () use ($token) {
66-
return !empty($token) ? $token : '';
67-
};
68-
return $this->valueFactory->create($result);
62+
try {
63+
$token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']);
64+
$result = function () use ($token) {
65+
return !empty($token) ? $token : '';
66+
};
67+
return $this->valueFactory->create($result);
68+
}catch (\Magento\Framework\Exception\AuthenticationException $e){
69+
throw new GraphQlAuthorizationException(
70+
__($e->getMessage())
71+
);
72+
}
6973
}
7074
}

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

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

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

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

0 commit comments

Comments
 (0)