-
Notifications
You must be signed in to change notification settings - Fork 9.4k
createCustomer validation requirements #28888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createCustomer validation requirements #28888
Conversation
…o 28570_createcustomer_graphql_schema
Hi @michalderlatka. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review. For more details, please, review the Magento Contributor Guide documentation. |
@magento run all tests |
@@ -0,0 +1,78 @@ | |||
<?php | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add copyright
array $value = null, | ||
array $args = null | ||
) { | ||
/** @var \Magento\GraphQl\Model\Query\ContextInterface $context */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add FQDN
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.')); | ||
} | ||
|
||
if (empty($args['email']) || empty($args['password'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this enforced by schema?
$customer = $this->getCustomer->execute($context); | ||
$this->updateCustomerAccount->execute( | ||
$customer, | ||
['email' => $args['email'], 'password' => $args['password']], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsafe array index, could cause an exception:
we usually do : $email = $args['email'] ?? null
I think the input is enforced by schema
try catch should take care of it, if you really want to show some error to graphql
@magento run all tests |
…(static test fix)
@magento run all tests |
@@ -17,14 +17,16 @@ type Query { | |||
type Mutation { | |||
generateCustomerToken(email: String!, password: String!): CustomerToken @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\GenerateCustomerToken") @doc(description:"Retrieve the customer token") | |||
changeCustomerPassword(currentPassword: String!, newPassword: String!): Customer @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\ChangePassword") @doc(description:"Changes the password for the logged-in customer") | |||
createCustomer (input: CustomerInput!): CustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\CreateCustomer") @doc(description:"Create customer account") | |||
updateCustomer (input: CustomerInput!): CustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomer") @doc(description:"Update the customer's personal information") | |||
createCustomer (input: CustomerCreateInput!): CustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\CreateCustomer") @doc(description:"Create customer account") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't change inputs on existing queries, so createCustomer (input: CustomerInput!): has to remain like this
and do a createCustomerV2 that uses CustomerCreateInput
@@ -116,14 +116,18 @@ public function testCreateCustomerAccountWithoutPassword() | |||
*/ | |||
public function testCreateCustomerIfInputDataIsEmpty() | |||
{ | |||
$exceptionMessage = 'Field CustomerCreateInput.email of required type String! was not provided. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a string either has "\n" or we can't do multi line strings like this. We usually don't add multi line exceptions
} | ||
|
||
/** | ||
* @inheritdoc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can add a proper description here
@magento run all tests |
@michalderlatka plz fix the static failures, some of those were exposed in the comments of the PR |
} | ||
|
||
/** | ||
* Resolves customer email update mutation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use "Resolve" imperative format. - you used Resolves as descriptive format
Also add params annotation
also add supress annotation, because not all params are used here:
PHP Code Mess has found error(s):
/var/www/html/app/code/Magento/CustomerGraphQl/Model/Resolver/UpdateCustomerEmail.php:58 Avoid unused parameters such as '$field'.
/var/www/html/app/code/Magento/CustomerGraphQl/Model/Resolver/UpdateCustomerEmail.php:60 Avoid unused parameters such as '$info'.
/var/www/html/app/code/Magento/CustomerGraphQl/Model/Resolver/UpdateCustomerEmail.php:61 Avoid unused parameters such as '$value'.
…(static test fix)
@magento run all tests |
@magento run all tests |
Hi @michalderlatka, thank you for your contribution! |
Description (*)
Currently createCustomer and updateCustomer are using same input CustomerInput. But for createCustomer some fields are required. Schema definition does not specify which ones are required. I followed https://github.com/magento/architecture/blob/master/design-documents/graph-ql/coverage/customer-email-password-update.md
and created newer mutation for customer update. Also createCustomer mutation will now use CustomerCreateInput which properly shows on schema level which fields are required.
Related Pull Requests
Fixed Issues (if relevant)
Fixes #28570
Manual testing scenarios (*)
Test customer mutations:
createCustomer
updateCustomerV2
updateCustomerEmail
Questions or comments
Contribution checklist (*)