Skip to content

Commit 1943018

Browse files
#28570: createCustomer does not match validation requirements
1 parent 02b87f6 commit 1943018

File tree

2 files changed

+110
-2
lines changed

2 files changed

+110
-2
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
4+
namespace Magento\CustomerGraphQl\Model\Resolver;
5+
6+
7+
use Magento\CustomerGraphQl\Model\Customer\ExtractCustomerData;
8+
use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
9+
use Magento\CustomerGraphQl\Model\Customer\UpdateCustomerAccount;
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
13+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
14+
use Magento\Framework\GraphQl\Query\Resolver\Value;
15+
use Magento\Framework\GraphQl\Query\ResolverInterface;
16+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17+
18+
class UpdateCustomerEmail implements ResolverInterface
19+
{
20+
/**
21+
* @var GetCustomer
22+
*/
23+
private $getCustomer;
24+
/**
25+
* @var UpdateCustomerAccount
26+
*/
27+
private $updateCustomerAccount;
28+
/**
29+
* @var ExtractCustomerData
30+
*/
31+
private $extractCustomerData;
32+
33+
/**
34+
* @param GetCustomer $getCustomer
35+
* @param UpdateCustomerAccount $updateCustomerAccount
36+
* @param ExtractCustomerData $extractCustomerData
37+
*/
38+
public function __construct(
39+
GetCustomer $getCustomer,
40+
UpdateCustomerAccount $updateCustomerAccount,
41+
ExtractCustomerData $extractCustomerData
42+
) {
43+
$this->getCustomer = $getCustomer;
44+
$this->updateCustomerAccount = $updateCustomerAccount;
45+
$this->extractCustomerData = $extractCustomerData;
46+
}
47+
48+
/**
49+
* @inheritdoc
50+
*/
51+
public function resolve(
52+
Field $field,
53+
$context,
54+
ResolveInfo $info,
55+
array $value = null,
56+
array $args = null
57+
) {
58+
/** @var \Magento\GraphQl\Model\Query\ContextInterface $context */
59+
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
60+
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
61+
}
62+
63+
if (empty($args['email']) || empty($args['password'])) {
64+
throw new GraphQlInputException(__('"email" and "password" values should be specified'));
65+
}
66+
67+
$customer = $this->getCustomer->execute($context);
68+
$this->updateCustomerAccount->execute(
69+
$customer,
70+
['email' => $args['email'], 'password' => $args['password']],
71+
$context->getExtensionAttributes()->getStore()
72+
);
73+
74+
$data = $this->extractCustomerData->execute($customer);
75+
76+
return ['customer' => $data];
77+
}
78+
}

app/code/Magento/CustomerGraphQl/etc/schema.graphqls

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ type Query {
1717
type Mutation {
1818
generateCustomerToken(email: String!, password: String!): CustomerToken @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\GenerateCustomerToken") @doc(description:"Retrieve the customer token")
1919
changeCustomerPassword(currentPassword: String!, newPassword: String!): Customer @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\ChangePassword") @doc(description:"Changes the password for the logged-in customer")
20-
createCustomer (input: CustomerInput!): CustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\CreateCustomer") @doc(description:"Create customer account")
21-
updateCustomer (input: CustomerInput!): CustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomer") @doc(description:"Update the customer's personal information")
20+
createCustomer (input: CustomerCreateInput!): CustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\CreateCustomer") @doc(description:"Create customer account")
21+
updateCustomer (input: CustomerInput!): CustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomer") @doc(description:"Deprecated. Use UpdateCustomerV2 instead.")
22+
updateCustomerV2 (input: CustomerUpdateInput!): CustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomer") @doc(description:"Update the customer's personal information")
2223
revokeCustomerToken: RevokeCustomerTokenOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\RevokeCustomerToken") @doc(description:"Revoke the customer token")
2324
createCustomerAddress(input: CustomerAddressInput!): CustomerAddress @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\CreateCustomerAddress") @doc(description: "Create customer address")
2425
updateCustomerAddress(id: Int!, input: CustomerAddressInput): CustomerAddress @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomerAddress") @doc(description: "Update customer address")
2526
deleteCustomerAddress(id: Int!): Boolean @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\DeleteCustomerAddress") @doc(description: "Delete customer address")
2627
requestPasswordResetEmail(email: String!): Boolean @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\RequestPasswordResetEmail") @doc(description: "Request an email with a reset password token for the registered customer identified by the specified email.")
2728
resetPassword(email: String!, resetPasswordToken: String!, newPassword: String!): Boolean @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\ResetPassword") @doc(description: "Reset a customer's password using the reset password token that the customer received in an email after requesting it using requestPasswordResetEmail.")
29+
updateCustomerEmail(email: String!, password: String!): CustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomerEmail") @doc(description: "")
2830
}
2931

3032
input CustomerAddressInput {
@@ -78,6 +80,34 @@ input CustomerInput {
7880
is_subscribed: Boolean @doc(description: "Indicates whether the customer is subscribed to the company's newsletter")
7981
}
8082

83+
input CustomerCreateInput {
84+
prefix: String @doc(description: "An honorific, such as Dr., Mr., or Mrs.")
85+
firstname: String! @doc(description: "The customer's first name")
86+
middlename: String @doc(description: "The customer's middle name")
87+
lastname: String! @doc(description: "The customer's family name")
88+
suffix: String @doc(description: "A value such as Sr., Jr., or III")
89+
email: String! @doc(description: "The customer's email address. Required for customer creation")
90+
dob: String @doc(description: "Deprecated: Use `date_of_birth` instead")
91+
date_of_birth: String @doc(description: "The customer's date of birth")
92+
taxvat: String @doc(description: "The customer's Tax/VAT number (for corporate customers)")
93+
gender: Int @doc(description: "The customer's gender (Male - 1, Female - 2)")
94+
password: String @doc(description: "The customer's password")
95+
is_subscribed: Boolean @doc(description: "Indicates whether the customer is subscribed to the company's newsletter")
96+
}
97+
98+
input CustomerUpdateInput {
99+
date_of_birth: String @doc(description: "The customer's date of birth")
100+
dob: String @doc(description: "Deprecated: Use `date_of_birth` instead")
101+
firstname: String @doc(description: "The customer's first name")
102+
gender: Int @doc(description: "The customer's gender (Male - 1, Female - 2)")
103+
is_subscribed: Boolean @doc(description: "Indicates whether the customer is subscribed to the company's newsletter")
104+
lastname: String @doc(description: "The customer's family name")
105+
middlename: String @doc(description: "The customer's middle name")
106+
prefix: String @doc(description: "An honorific, such as Dr., Mr., or Mrs.")
107+
suffix: String @doc(description: "A value such as Sr., Jr., or III")
108+
taxvat: String @doc(description: "The customer's Tax/VAT number (for corporate customers)")
109+
}
110+
81111
type CustomerOutput {
82112
customer: Customer!
83113
}

0 commit comments

Comments
 (0)