File tree 4 files changed +152
-0
lines changed
app/code/Magento/CustomerGraphQl
dev/tests/api-functional/testsuite/Magento/GraphQl/Customer 4 files changed +152
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \CustomerGraphQl \Model \Customer ;
9
+
10
+ use Magento \Customer \Api \AccountManagementInterface ;
11
+
12
+ /**
13
+ * Is Customer Email Available checker
14
+ */
15
+ class IsEmailAvailableDataProvider
16
+ {
17
+ /**
18
+ * @var AccountManagementInterface
19
+ */
20
+ private $ accountManagement ;
21
+
22
+ /**
23
+ * @param AccountManagementInterface $accountManagement
24
+ */
25
+ public function __construct (AccountManagementInterface $ accountManagement )
26
+ {
27
+ $ this ->accountManagement = $ accountManagement ;
28
+ }
29
+
30
+ /**
31
+ * Check is Email available
32
+ *
33
+ * @param string $email
34
+ * @return bool
35
+ */
36
+ public function execute (string $ email ): bool
37
+ {
38
+ return $ this ->accountManagement ->isEmailAvailable ($ email );
39
+ }
40
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \CustomerGraphQl \Model \Resolver ;
9
+
10
+ use Magento \CustomerGraphQl \Model \Customer \IsEmailAvailableDataProvider ;
11
+ use Magento \Framework \GraphQl \Config \Element \Field ;
12
+ use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
13
+ use Magento \Framework \GraphQl \Query \ResolverInterface ;
14
+ use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
15
+
16
+ /**
17
+ * Is Customer Email Available
18
+ */
19
+ class IsEmailAvailable implements ResolverInterface
20
+ {
21
+ /**
22
+ * @var IsEmailAvailableDataProvider
23
+ */
24
+ private $ isEmailAvailableDataProvider ;
25
+
26
+ /**
27
+ * @param IsEmailAvailableDataProvider $isEmailAvailableDataProvider
28
+ */
29
+ public function __construct (
30
+ IsEmailAvailableDataProvider $ isEmailAvailableDataProvider
31
+ ) {
32
+ $ this ->isEmailAvailableDataProvider = $ isEmailAvailableDataProvider ;
33
+ }
34
+
35
+ /**
36
+ * @inheritdoc
37
+ */
38
+ public function resolve (
39
+ Field $ field ,
40
+ $ context ,
41
+ ResolveInfo $ info ,
42
+ array $ value = null ,
43
+ array $ args = null
44
+ ) {
45
+ $ email = $ args ['email ' ] ?? null ;
46
+ if (!$ email ) {
47
+ throw new GraphQlInputException (__ ('"Email should be specified ' ));
48
+ }
49
+ $ isEmailAvailable = $ this ->isEmailAvailableDataProvider ->execute ($ email );
50
+
51
+ return [
52
+ 'is_email_available ' => $ isEmailAvailable
53
+ ];
54
+ }
55
+ }
Original file line number Diff line number Diff line change 3
3
4
4
type Query {
5
5
customer : Customer @resolver (class : " Magento\\ CustomerGraphQl\\ Model\\ Resolver\\ Customer" ) @doc (description : " The customer query returns information about a customer account" )
6
+ isEmailAvailable (
7
+ email : String ! @doc (description : " The new customer email" )
8
+ ): IsEmailAvailableOutput @resolver (class : " Magento\\ CustomerGraphQl\\ Model\\ Resolver\\ IsEmailAvailable" )
6
9
}
7
10
8
11
type Mutation {
@@ -126,6 +129,10 @@ type CustomerAddressAttribute {
126
129
value : String @doc (description : " Attribute value" )
127
130
}
128
131
132
+ type IsEmailAvailableOutput {
133
+ is_email_available : Boolean @doc (description : " Is email availabel value" )
134
+ }
135
+
129
136
enum CountryCodeEnum @doc (description : " The list of countries codes" ) {
130
137
AF @doc (description : " Afghanistan" )
131
138
AX @doc (description : " Åland Islands" )
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \GraphQl \Customer ;
9
+
10
+ use Magento \TestFramework \TestCase \GraphQlAbstract ;
11
+
12
+ class IsEmailAvailableTest extends GraphQlAbstract
13
+ {
14
+ /**
15
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
16
+ */
17
+ public function testEmailNotAvailable ()
18
+ {
19
+ $ query =
20
+ <<<QUERY
21
+ {
22
+ isEmailAvailable(email: "[email protected] ") {
23
+ is_email_available
24
+ }
25
+ }
26
+ QUERY ;
27
+ $ response = $ this ->graphQlQuery ($ query );
28
+
29
+ self ::assertArrayHasKey ('isEmailAvailable ' , $ response );
30
+ self ::assertArrayHasKey ('is_email_available ' , $ response ['isEmailAvailable ' ]);
31
+ self ::assertFalse ($ response ['isEmailAvailable ' ]['is_email_available ' ]);
32
+ }
33
+
34
+ public function testEmailAvailable ()
35
+ {
36
+ $ query =
37
+ <<<QUERY
38
+ {
39
+ isEmailAvailable(email: "[email protected] ") {
40
+ is_email_available
41
+ }
42
+ }
43
+ QUERY ;
44
+ $ response = $ this ->graphQlQuery ($ query );
45
+
46
+ self ::assertArrayHasKey ('isEmailAvailable ' , $ response );
47
+ self ::assertArrayHasKey ('is_email_available ' , $ response ['isEmailAvailable ' ]);
48
+ self ::assertTrue ($ response ['isEmailAvailable ' ]['is_email_available ' ]);
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments