Skip to content

Commit

Permalink
GraphQL-129: Change generate token schema and add graphql exception
Browse files Browse the repository at this point in the history
  • Loading branch information
pfantini committed Sep 8, 2018
1 parent 527e4fe commit ea9b2a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
}
}
}
6 changes: 1 addition & 5 deletions app/code/Magento/CustomerGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit ea9b2a8

Please sign in to comment.