This repository was archived by the owner on Dec 19, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +112
-0
lines changed
app/code/Magento/CustomerGraphQl
dev/tests/api-functional/testsuite/Magento/GraphQl/Customer Expand file tree Collapse file tree 3 files changed +112
-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 \Resolver ;
9+
10+ use Magento \Customer \Api \AccountManagementInterface ;
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 AccountManagementInterface
23+ */
24+ private $ accountManagement ;
25+
26+ /**
27+ * @param AccountManagementInterface $accountManagement
28+ */
29+ public function __construct (
30+ AccountManagementInterface $ accountManagement
31+ ) {
32+ $ this ->accountManagement = $ accountManagement ;
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 ->accountManagement ->isEmailAvailable ($ email );
50+
51+ return [
52+ 'is_email_available ' => $ isEmailAvailable
53+ ];
54+ }
55+ }
Original file line number Diff line number Diff line change 33
44type Query {
55 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" )
69}
710
811type Mutation {
@@ -126,6 +129,10 @@ type CustomerAddressAttribute {
126129 value : String @doc (description : " Attribute value" )
127130}
128131
132+ type IsEmailAvailableOutput {
133+ is_email_available : Boolean @doc (description : " Is email availabel value" )
134+ }
135+
129136enum CountryCodeEnum @doc (description : " The list of countries codes" ) {
130137 AF @doc (description : " Afghanistan" )
131138 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