Skip to content

Saleor Core: the high performance, composable, headless commerce API.

[SALEOR-4568] Extend account register mutation (#8184)

Piotr Grundaseb5beab591e2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5267758999..6dfd823b19 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Fix shipping address issue in `availableCollectionPoints` resolver for checkout - #8143 by @kuchichan
- Improve draft orders and orders webhooks by @jakubkuc
- Fix cursor-based pagination in products search - #8011 by @rafalp
+- Extend `accountRegister` mutation to consume first & last name - #8184 by @piotrgrundas
# 3.0.0 [Unreleased]
diff --git a/saleor/graphql/account/mutations/account.py b/saleor/graphql/account/mutations/account.py
index 2e6bcfc90b..9ad78b6b3c 100644
--- a/saleor/graphql/account/mutations/account.py
+++ b/saleor/graphql/account/mutations/account.py
@@ -29,9 +29,19 @@ from .base import (
)
-class AccountRegisterInput(graphene.InputObjectType):
+class AccountBaseInput(graphene.InputObjectType):
+ first_name = graphene.String(description="Given name.")
+ last_name = graphene.String(description="Family name.")
+ language_code = graphene.Argument(
+ LanguageCodeEnum, required=False, description="User language code."
+ )
+
+
+class AccountRegisterInput(AccountBaseInput):
email = graphene.String(description="The email address of the user.", required=True)
password = graphene.String(description="Password.", required=True)
+ first_name = graphene.String(description="Given name.")
+ last_name = graphene.String(description="Family name.")
redirect_url = graphene.String(
description=(
"Base of frontend URL that will be needed to create confirmation URL."
@@ -137,18 +147,13 @@ class AccountRegister(ModelMutation):
info.context.plugins.customer_created(customer=user)
-class AccountInput(graphene.InputObjectType):
- first_name = graphene.String(description="Given name.")
- last_name = graphene.String(description="Family name.")
+class AccountInput(AccountBaseInput):
default_billing_address = AddressInput(
description="Billing address of the customer."
)
default_shipping_address = AddressInput(
description="Shipping address of the customer."
)
- language_code = graphene.Argument(
- LanguageCodeEnum, required=False, description="User language code."
- )
class AccountUpdate(BaseCustomerCreate):
diff --git a/saleor/graphql/account/tests/test_account.py b/saleor/graphql/account/tests/test_account.py
index c5c4f2dffd..ef99aa0a4f 100644
--- a/saleor/graphql/account/tests/test_account.py
+++ b/saleor/graphql/account/tests/test_account.py
@@ -1021,6 +1021,8 @@ ACCOUNT_REGISTER_MUTATION = """
mutation RegisterAccount(
$password: String!,
$email: String!,
+ $firstName: String,
+ $lastName: String,
$redirectUrl: String,
$languageCode: LanguageCodeEnum
$metadata: [MetadataInput!],
@@ -1030,6 +1032,8 @@ ACCOUNT_REGISTER_MUTATION = """
input: {
password: $password,
email: $email,
+ firstName: $firstName,
+ lastName: $lastName,
redirectUrl: $redirectUrl,
languageCode: $languageCode,
metadata: $metadata,
@@ -1062,6 +1066,8 @@ def test_customer_register(mocked_notify, mocked_generator, api_client, channel_
"email": email,
"password": "Password",
"redirectUrl": redirect_url,
+ "firstName": "saleor",
+ "lastName": "rocks",
"languageCode": "PL",
"metadata": [{"key": "meta", "value": "data"}],
"channel": channel_PLN.slug,
@@ -1076,6 +1082,7 @@ def test_customer_register(mocked_notify, mocked_generator, api_client, channel_
data = content["data"][mutation_name]
params = urlencode({"email": email, "token": "token"})
confirm_url = prepare_url(params, redirect_url)
+
expected_payload = {
"user": get_default_user_payload(new_user),
"token": "token",
@@ -1087,6 +1094,8 @@ def test_customer_register(mocked_notify, mocked_generator, api_client, channel_
}
assert new_user.metadata == {"meta": "data"}
assert new_user.language_code == "pl"
+ assert new_user.first_name == variables["firstName"]
+ assert new_user.last_name == variables["lastName"]
assert not data["errors"]
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_CONFIRMATION,
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 159f75e0b9..e832a240c8 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -75,9 +75,9 @@ enum AccountErrorCode {
input AccountInput {
firstName: String
lastName: String
+ languageCode: LanguageCodeEnum
defaultBillingAddress: AddressInput
defaultShippingAddress: AddressInput
- languageCode: LanguageCodeEnum
}
type AccountRegister {
@@ -88,10 +88,12 @@ type AccountRegister {
}
input AccountRegisterInput {
+ firstName: String
+ lastName: String
+ languageCode: LanguageCodeEnum
email: String!
password: String!
redirectUrl: String
- languageCode: LanguageCodeEnum
metadata: [MetadataInput!]
channel: String
}