From ea9b2a8a73da00df665da807b830615c129945fc Mon Sep 17 00:00:00 2001 From: Pablo Fantini Date: Sat, 8 Sep 2018 15:47:11 -0300 Subject: [PATCH] GraphQL-129: Change generate token schema and add graphql exception --- .../Customer/Account/GenerateCustomerToken.php | 18 +++++++++++------- .../CustomerGraphQl/etc/schema.graphqls | 6 +----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php index 7a76caddfff63..466aad1c0348f 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php @@ -59,12 +59,16 @@ public function resolve( array $value = null, array $args = null ): Value { - - $token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']); - //TODO: exception - $result = function () use ($token) { - return !empty($token) ? $token : ''; - }; - return $this->valueFactory->create($result); + try { + $token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']); + $result = function () use ($token) { + return !empty($token) ? $token : ''; + }; + return $this->valueFactory->create($result); + }catch (\Magento\Framework\Exception\AuthenticationException $e){ + throw new GraphQlAuthorizationException( + __($e->getMessage()) + ); + } } } diff --git a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls index 76268b5622b68..0aaa869a6641d 100644 --- a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls @@ -6,11 +6,7 @@ type Query { } type Mutation { - generateCustomerToken(email: String!, password: String!): GenerateCustomerTokenOutput! @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\GenerateCustomerToken") @doc(description:"Retrieve Customer token") -} - -type GenerateCustomerTokenOutput { - token: String! @doc(description: "The customer token") + generateCustomerToken(email: String!, password: String!): String! @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\GenerateCustomerToken") @doc(description:"Retrieve Customer token") } type Customer @doc(description: "Customer defines the customer name and address and other details") {