Skip to content

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

Allow passing metadata to `accountRegister` mutation (#7152)

Piotr Grundas6ca272982f4b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 70bd2ed1db..8fb703fa2f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -54,6 +54,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Extend Vatlayer functionalities - #7101 by @korycins:
- Allow users to enter a list of exceptions (country ISO codes) that will use the source country rather than the destination country for tax purposes.
- Allow users to enter a list of countries for which no VAT will be added.
+- Allow passing metadata to `accountRegister` mutation - #7152 by @piotrgrundas
- Fix incorrect payment data for klarna - #7150 by @IKarbowiak
- Drop deleted images from storage - #7129 by @IKarbowiak
diff --git a/saleor/graphql/account/mutations/account.py b/saleor/graphql/account/mutations/account.py
index cabb78feb3..75fad0f168 100644
--- a/saleor/graphql/account/mutations/account.py
+++ b/saleor/graphql/account/mutations/account.py
@@ -17,6 +17,7 @@ from ...account.types import Address, AddressInput, User
from ...core.enums import LanguageCodeEnum
from ...core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation
from ...core.types.common import AccountError
+from ...meta.mutations import MetadataInput
from ..i18n import I18nMixin
from .base import (
INVALID_TOKEN,
@@ -38,6 +39,11 @@ class AccountRegisterInput(graphene.InputObjectType):
language_code = graphene.Argument(
LanguageCodeEnum, required=False, description="User language code."
)
+ metadata = graphene.List(
+ graphene.NonNull(MetadataInput),
+ description="User public metadata.",
+ required=False,
+ )
class AccountRegister(ModelMutation):
@@ -65,6 +71,9 @@ class AccountRegister(ModelMutation):
@classmethod
def clean_input(cls, info, instance, data, input_cls=None):
+ data["metadata"] = {
+ item["key"]: item["value"] for item in data.get("metadata") or []
+ }
if not settings.ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL:
return super().clean_input(info, instance, data, input_cls=None)
elif not data.get("redirect_url"):
diff --git a/saleor/graphql/account/tests/test_account.py b/saleor/graphql/account/tests/test_account.py
index db96974f9f..c154c6e544 100644
--- a/saleor/graphql/account/tests/test_account.py
+++ b/saleor/graphql/account/tests/test_account.py
@@ -958,6 +958,7 @@ ACCOUNT_REGISTER_MUTATION = """
$email: String!,
$redirectUrl: String,
$languageCode: LanguageCodeEnum
+ $metadata: [MetadataInput!]
) {
accountRegister(
input: {
@@ -965,6 +966,7 @@ ACCOUNT_REGISTER_MUTATION = """
email: $email,
redirectUrl: $redirectUrl,
languageCode: $languageCode,
+ metadata: $metadata
}
) {
accountErrors {
@@ -994,6 +996,7 @@ def test_customer_register(mocked_notify, mocked_generator, api_client):
"password": "Password",
"redirectUrl": redirect_url,
"languageCode": "PL",
+ "metadata": [{"key": "meta", "value": "data"}],
}
query = ACCOUNT_REGISTER_MUTATION
mutation_name = "accountRegister"
@@ -1013,6 +1016,7 @@ def test_customer_register(mocked_notify, mocked_generator, api_client):
"site_name": "mirumee.com",
"domain": "mirumee.com",
}
+ assert new_user.metadata == {"meta": "data"}
assert new_user.language_code == "pl"
assert not data["accountErrors"]
mocked_notify.assert_called_once_with(
@@ -1435,8 +1439,12 @@ def test_customer_update_without_any_changes_generates_no_event(
ACCOUNT_UPDATE_QUERY = """
mutation accountUpdate(
- $billing: AddressInput, $shipping: AddressInput, $firstName: String,
- $lastName: String, $languageCode: LanguageCodeEnum) {
+ $billing: AddressInput
+ $shipping: AddressInput
+ $firstName: String,
+ $lastName: String
+ $languageCode: LanguageCodeEnum
+ ) {
accountUpdate(
input: {
defaultBillingAddress: $billing,
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 7f5aec170c..4f6c3977a3 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -89,6 +89,7 @@ input AccountRegisterInput {
password: String!
redirectUrl: String
languageCode: LanguageCodeEnum
+ metadata: [MetadataInput!]
}
type AccountRequestDeletion {