Skip to content

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

Conversation

michalderlatka
Copy link
Contributor

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 (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jun 25, 2020

Hi @michalderlatka. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

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.

@michalderlatka
Copy link
Contributor Author

@magento run all tests

@ghost ghost assigned cpartica Jun 26, 2020
@@ -0,0 +1,78 @@
<?php

Copy link
Contributor

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 */
Copy link
Contributor

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'])) {
Copy link
Contributor

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']],
Copy link
Contributor

@cpartica cpartica Jun 26, 2020

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

@michalderlatka
Copy link
Contributor Author

@magento run all tests

@michalderlatka
Copy link
Contributor Author

@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")
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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

@michalderlatka
Copy link
Contributor Author

@magento run all tests

@cpartica
Copy link
Contributor

cpartica commented Jul 9, 2020

@michalderlatka plz fix the static failures, some of those were exposed in the comments of the PR

}

/**
* Resolves customer email update mutation
Copy link
Contributor

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'.

@michalderlatka
Copy link
Contributor Author

@magento run all tests

@nrkapoor nrkapoor added this to the 2.4.1 milestone Jul 14, 2020
@cpartica
Copy link
Contributor

@magento run all tests

@m2-assistant
Copy link

m2-assistant bot commented Jul 16, 2020

Hi @michalderlatka, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

GraphQL Schema for createCustomer does not match validation requirements
4 participants