Skip to content

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

Add first and last name in graphql

fowczarek5e8431e2ace8
diff --git a/saleor/graphql/account/mutations.py b/saleor/graphql/account/mutations.py
index 2fe9d67ced..f14013f508 100644
--- a/saleor/graphql/account/mutations.py
+++ b/saleor/graphql/account/mutations.py
@@ -55,6 +55,8 @@ class CustomerRegister(ModelMutation):
class UserInput(graphene.InputObjectType):
+ first_name = graphene.String(description='Given name.')
+ last_name = graphene.String(description='Family name.')
email = graphene.String(
description='The unique email address of the user.')
is_active = graphene.Boolean(
diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.py
index a926af9756..a99bcad12d 100644
--- a/saleor/graphql/account/resolvers.py
+++ b/saleor/graphql/account/resolvers.py
@@ -8,7 +8,8 @@ from ..utils import filter_by_query_param
from .types import AddressValidationData, ChoiceValue
USER_SEARCH_FIELDS = (
- 'email', 'default_shipping_address__first_name',
+ 'email', 'first_name', 'last_name',
+ 'default_shipping_address__first_name',
'default_shipping_address__last_name', 'default_shipping_address__city',
'default_shipping_address__country')
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index faf7c8cdef..52171c38e4 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -89,6 +89,8 @@ def test_query_user(staff_api_client, customer_user, permission_manage_users):
query User($id: ID!) {
user(id: $id) {
email
+ firstName
+ lastName
isStaff
isActive
addresses {
@@ -124,6 +126,8 @@ def test_query_user(staff_api_client, customer_user, permission_manage_users):
content = get_graphql_content(response)
data = content['data']['user']
assert data['email'] == user.email
+ assert data['firstName'] == user.first_name
+ assert data['lastName'] == user.last_name
assert data['isStaff'] == user.is_staff
assert data['isActive'] == user.is_active
assert len(data['addresses']) == user.addresses.count()
@@ -338,10 +342,13 @@ def test_customer_create(
permission_manage_users):
query = """
mutation CreateCustomer(
- $email: String, $note: String, $billing: AddressInput,
- $shipping: AddressInput, $send_mail: Boolean) {
+ $email: String, $firstName: String, $lastName: String,
+ $note: String, $billing: AddressInput, $shipping: AddressInput,
+ $send_mail: Boolean) {
customerCreate(input: {
email: $email,
+ firstName: $firstName,
+ lastName: $lastName,
note: $note,
defaultShippingAddress: $shipping,
defaultBillingAddress: $billing
@@ -360,6 +367,8 @@ def test_customer_create(
id
}
email
+ firstName
+ lastName
isActive
isStaff
note
@@ -368,11 +377,15 @@ def test_customer_create(
}
"""
+ first_name = "api_first_name"
+ last_name = "api_last_name"
note = 'Test user'
address_data = convert_dict_keys_to_camel_case(address.as_data())
variables = {
'email': email,
+ 'firstName': first_name,
+ 'lastName': last_name,
'note': note,
'shipping': address_data,
'billing': address_data,
@@ -392,6 +405,8 @@ def test_customer_create(
data = content['data']['customerCreate']
assert data['errors'] == []
assert data['user']['email'] == email
+ assert data['user']['firstName'] == first_name
+ assert data['user']['lastName'] == last_name
assert data['user']['note'] == note
assert data['user']['isStaff'] == False
assert data['user']['isActive'] == True
@@ -407,9 +422,11 @@ def test_customer_create(
def test_customer_update(
staff_api_client, customer_user, address, permission_manage_users):
query = """
- mutation UpdateCustomer($id: ID!, $isActive: Boolean, $note: String, $billing: AddressInput, $shipping: AddressInput) {
+ mutation UpdateCustomer($id: ID!, $firstName: String, $lastName: String, $isActive: Boolean, $note: String, $billing: AddressInput, $shipping: AddressInput) {
customerUpdate(id: $id, input: {
isActive: $isActive,
+ firstName: $firstName,
+ lastName: $lastName,
note: $note,
defaultBillingAddress: $billing
defaultShippingAddress: $shipping
@@ -420,6 +437,8 @@ def test_customer_update(
}
user {
id
+ firstName
+ lastName
defaultBillingAddress {
id
}
@@ -441,6 +460,8 @@ def test_customer_update(
shipping_address_pk = customer_user.default_shipping_address.pk
id = graphene.Node.to_global_id('User', customer_user.id)
+ first_name = 'new_first_name'
+ last_name = 'new_last_name'
note = 'Test update note'
address_data = convert_dict_keys_to_camel_case(address.as_data())
@@ -448,7 +469,12 @@ def test_customer_update(
address_data['streetAddress1'] = new_street_address
variables = {
- 'id': id, 'isActive': False, 'note': note, 'billing': address_data,
+ 'id': id,
+ 'firstName': first_name,
+ 'lastName': last_name,
+ 'isActive': False,
+ 'note': note,
+ 'billing': address_data,
'shipping': address_data}
response = staff_api_client.post_graphql(
query, variables, permissions=[permission_manage_users])
@@ -466,6 +492,8 @@ def test_customer_update(
data = content['data']['customerUpdate']
assert data['errors'] == []
+ assert data['user']['firstName'] == first_name
+ assert data['user']['lastName'] == last_name
assert data['user']['note'] == note
assert not data['user']['isActive']