Skip to content

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

Add mutation for update account first and last name

fowczarek70fd877a6cc6
diff --git a/saleor/graphql/account/mutations.py b/saleor/graphql/account/mutations.py
index a831402222..a9b72ecdf6 100644
--- a/saleor/graphql/account/mutations.py
+++ b/saleor/graphql/account/mutations.py
@@ -116,6 +116,17 @@ class StaffInput(UserInput):
)
+class AccountInput(graphene.InputObjectType):
+ first_name = graphene.String(description="Given name.")
+ last_name = graphene.String(description="Family name.")
+ default_billing_address = AddressInput(
+ description="Billing address of the customer."
+ )
+ default_shipping_address = AddressInput(
+ description="Shipping address of the customer."
+ )
+
+
class StaffCreateInput(StaffInput):
send_password_email = graphene.Boolean(
description="Send an email with a link to set a password"
@@ -260,6 +271,28 @@ class LoggedUserUpdate(CustomerCreate):
return super().perform_mutation(root, info, **data)
+class AccountUpdate(CustomerCreate):
+ class Arguments:
+ input = AccountInput(
+ description="Fields required to update logged in user.", required=True
+ )
+
+ class Meta:
+ description = "Updates data of the logged in user."
+ exclude = ["password", "note"]
+ model = models.User
+
+ @classmethod
+ def check_permissions(cls, user):
+ return user.is_authenticated
+
+ @classmethod
+ def perform_mutation(cls, root, info, **data):
+ user = info.context.user
+ data["id"] = graphene.Node.to_global_id("User", user.id)
+ return super().perform_mutation(root, info, **data)
+
+
class UserDelete(UserDeleteMixin, ModelDeleteMutation):
class Meta:
abstract = True
diff --git a/saleor/graphql/account/schema.py b/saleor/graphql/account/schema.py
index 93301ec29c..0a1a812d15 100644
--- a/saleor/graphql/account/schema.py
+++ b/saleor/graphql/account/schema.py
@@ -8,6 +8,7 @@ from .bulk_mutations import CustomerBulkDelete, StaffBulkDelete, UserBulkSetActi
from .enums import CountryCodeEnum
from .filters import CustomerFilter, StaffUserFilter
from .mutations import (
+ AccountUpdate,
AddressCreate,
AddressDelete,
AddressSetDefault,
@@ -109,6 +110,7 @@ class AccountMutations(graphene.ObjectType):
customer_set_default_address = CustomerSetDefaultAddress.Field()
logged_user_update = LoggedUserUpdate.Field()
+ account_update = AccountUpdate.Field()
staff_create = StaffCreate.Field()
staff_delete = StaffDelete.Field()