Skip to content

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

Return product type in attribute mutations

Marcin Gębala3d12718296e1
diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.py
index 47906ff647..ebbab74605 100644
--- a/saleor/graphql/product/mutations/attributes.py
+++ b/saleor/graphql/product/mutations/attributes.py
@@ -243,8 +243,17 @@ class AttributeUpdate(AttributeMixin, ModelMutation):
for attribute_value in cleaned_data.get('remove_values', []):
attribute_value.delete()
+ @classmethod
+ def success_response(cls, instance):
+ response = super().success_response(instance)
+ response.product_type = instance.product_type
+ return response
+
class AttributeDelete(ModelDeleteMutation):
+ product_type = graphene.Field(
+ ProductType, description='A related product type.')
+
class Arguments:
id = graphene.ID(
required=True, description='ID of an attribute to delete.')
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 2ba2ecdb11..1412b6c8e6 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -140,6 +140,7 @@ input AttributeCreateValueInput {
type AttributeDelete {
errors: [Error]
+ productType: ProductType
attribute: Attribute
}
diff --git a/tests/api/test_attributes.py b/tests/api/test_attributes.py
index b94b5dbc9c..edd8ae6a2f 100644
--- a/tests/api/test_attributes.py
+++ b/tests/api/test_attributes.py
@@ -105,6 +105,10 @@ CREATE_ATTRIBUTES_QUERY = """
slug
}
}
+ productType {
+ id
+ name
+ }
}
}
"""
@@ -125,15 +129,16 @@ def test_create_attribute_and_attribute_values(
query, variables, permissions=[permission_manage_products])
content = get_graphql_content(response)
assert not content['data']['attributeCreate']['errors']
- data = content['data']['attributeCreate']['attribute']
- assert data['name'] == attribute_name
- assert data['slug'] == slugify(attribute_name)
+ data = content['data']['attributeCreate']
+ assert data['attribute']['name'] == attribute_name
+ assert data['attribute']['slug'] == slugify(attribute_name)
- assert len(data['values']) == 1
- assert data['values'][0]['name'] == name
- assert data['values'][0]['slug'] == slugify(name)
+ assert len(data['attribute']['values']) == 1
+ assert data['attribute']['values'][0]['name'] == name
+ assert data['attribute']['values'][0]['slug'] == slugify(name)
attribute = Attribute.objects.get(name=attribute_name)
assert attribute in product_type.product_attributes.all()
+ assert data['productType']['name'] == product_type.name
@pytest.mark.parametrize(
@@ -236,13 +241,18 @@ UPDATE_ATTRIBUTE_QUERY = """
slug
}
}
+ productType {
+ id
+ name
+ }
}
}
"""
def test_update_attribute_name(
- staff_api_client, color_attribute, permission_manage_products):
+ staff_api_client, color_attribute, product_type,
+ permission_manage_products):
query = UPDATE_ATTRIBUTE_QUERY
attribute = color_attribute
name = 'Wings name'
@@ -254,6 +264,7 @@ def test_update_attribute_name(
attribute.refresh_from_db()
data = content['data']['attributeUpdate']
assert data['attribute']['name'] == name == attribute.name
+ assert data['productType']['name'] == attribute.product_type.name
def test_update_attribute_remove_and_add_values(