Skip to content

Commit 08cd57b

Browse files
Merge pull request #2 from raivisdejus/master
Adding endpoint to check email address availability
2 parents 536a09f + 5803648 commit 08cd57b

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* ScandiPWA - Progressive Web App for Magento
4+
*
5+
* Copyright © Scandiweb, Inc. All rights reserved.
6+
* See LICENSE for license details.
7+
*
8+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
9+
* @package scandipwa/module-customer-graph-ql
10+
* @link https://github.com/scandipwa/module-customer-graph-ql
11+
*/
12+
declare(strict_types=1);
13+
14+
namespace ScandiPWA\CustomerGraphQl\Model\Resolver;
15+
16+
use Magento\Customer\Api\AccountManagementInterface;
17+
use Magento\Framework\GraphQl\Config\Element\Field;
18+
use Magento\Framework\GraphQl\Query\ResolverInterface;
19+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
20+
21+
class CheckIsEmailAvailable implements ResolverInterface {
22+
/**
23+
* @var \Magento\Customer\Api\AccountManagementInterface
24+
*/
25+
protected $accountManagement;
26+
27+
/**
28+
* ResendConfirmationEmail constructor.
29+
* @param AccountManagementInterface $accountManagement
30+
*/
31+
public function __construct(
32+
AccountManagementInterface $accountManagement
33+
) {
34+
$this->accountManagement = $accountManagement;
35+
}
36+
37+
/**
38+
* @inheritdoc
39+
*/
40+
public function resolve(
41+
Field $field,
42+
$context,
43+
ResolveInfo $info,
44+
array $value = null,
45+
array $args = null
46+
) {
47+
$email = $args['email'];
48+
$websiteId = isset($args['websiteId']) ? $args['websiteId'] : null;
49+
50+
$result = $this->accountManagement->isEmailAvailable(
51+
$email,
52+
$websiteId
53+
);
54+
55+
return ['isAvailable' => $result];
56+
}
57+
}

src/etc/schema.graphqls

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Mutation {
1616
resendConfirmationEmail(email: String!): CustomerActionConfirmationType @resolver(class: "\\ScandiPWA\\CustomerGraphQl\\Model\\Resolver\\ResendConfirmationEmail") @doc(description:"Resend customer confirmation")
1717
forgotPassword(email: String!): CustomerActionConfirmationType @resolver(class: "\\ScandiPWA\\CustomerGraphQl\\Model\\Resolver\\ForgotPassword") @doc(description:"Resend customer confirmation")
1818
resetPassword(password: String!, token: String!, password_confirmation: String!): ResetPasswordType @resolver(class: "\\ScandiPWA\\CustomerGraphQl\\Model\\Resolver\\ResetPassword") @doc(description:"Resend customer confirmation")
19+
checkIsEmailAvailable(email: String!, websiteId: Int): AvailabilityResponseType @resolver(class: "\\ScandiPWA\\CustomerGraphQl\\Model\\Resolver\\CheckIsEmailAvailable") @doc(description:"Check if custmer email is available")
1920
}
2021

2122
type CustomerActionConfirmationType {
@@ -32,3 +33,7 @@ type CreateCustomerType {
3233
token: String @doc(description: "The customer token")
3334
customer: Customer
3435
}
36+
37+
type AvailabilityResponseType {
38+
isAvailable: Boolean
39+
}

0 commit comments

Comments
 (0)