Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Support setting value for AttributeValue mutations
Piotr Grundas81a57ddc739e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8e4e5b1c89..278d61b878 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -25,6 +25,7 @@ All notable, unreleased changes to this project will be documented in this file.- Raise an error when the user is trying to sort products by rank without search - #7013 by @IKarbowiak- Fix available shipping methods - return also weight methods without weight limits - #7021 by @IKarbowiak- Remove redundant Opentracing spans - #6994 by @fowczarek+- Support setting value for AttributeValue mutations - #7037 by @piotrgrundas### Breaking- Multichannel MVP: Multicurrency - #6242 by @fowczarek @d-wysockidiff --git a/saleor/graphql/attribute/descriptions.py b/saleor/graphql/attribute/descriptions.pyindex 027d929948..4b5bf5b2e8 100644--- a/saleor/graphql/attribute/descriptions.py+++ b/saleor/graphql/attribute/descriptions.py@@ -26,3 +26,4 @@ class AttributeValueDescriptions:SLUG = "Internal representation of a value (unique per attribute)."TYPE = "Type of value (used only when `value` field is set)."FILE = "Represents file URL and content type (if attribute value is a file)."+ VALUE = "Represents value of the attribute value"diff --git a/saleor/graphql/attribute/mutations.py b/saleor/graphql/attribute/mutations.pyindex 921d0ba4d3..68841045df 100644--- a/saleor/graphql/attribute/mutations.py+++ b/saleor/graphql/attribute/mutations.py@@ -189,6 +189,7 @@ class BaseReorderAttributeValuesMutation(BaseMutation):class AttributeValueCreateInput(graphene.InputObjectType):name = graphene.String(required=True, description=AttributeValueDescriptions.NAME)+ value = graphene.String(description=AttributeValueDescriptions.VALUE)class AttributeCreateInput(graphene.InputObjectType):diff --git a/saleor/graphql/attribute/tests/mutations/test_attribute_create.py b/saleor/graphql/attribute/tests/mutations/test_attribute_create.pyindex 209b0d20ba..a8cd5b103f 100644--- a/saleor/graphql/attribute/tests/mutations/test_attribute_create.py+++ b/saleor/graphql/attribute/tests/mutations/test_attribute_create.py@@ -28,6 +28,7 @@ CREATE_ATTRIBUTE_MUTATION = """values {nameslug+ value}productTypes(first: 10) {edges {@@ -52,10 +53,11 @@ def test_create_attribute_and_attribute_values(attribute_name = "Example name"name = "Value name"+ value = "Value"variables = {"input": {"name": attribute_name,- "values": [{"name": name}],+ "values": [{"name": name, "value": value}],"type": AttributeTypeEnum.PRODUCT_TYPE.name,}}@@ -89,6 +91,7 @@ def test_create_attribute_and_attribute_values(assert data["attribute"]["type"] == AttributeTypeEnum.PRODUCT_TYPE.nameassert data["attribute"]["values"][0]["name"] == nameassert data["attribute"]["values"][0]["slug"] == slugify(name)+ assert data["attribute"]["values"][0]["value"] == valuedef test_create_attribute_with_file_input_type(diff --git a/saleor/graphql/attribute/tests/mutations/test_attribute_value_create.py b/saleor/graphql/attribute/tests/mutations/test_attribute_value_create.pyindex 5b1a4e55ff..35367a3fb6 100644--- a/saleor/graphql/attribute/tests/mutations/test_attribute_value_create.py+++ b/saleor/graphql/attribute/tests/mutations/test_attribute_value_create.py@@ -27,9 +27,9 @@ def test_validate_value_is_unique(color_attribute):CREATE_ATTRIBUTE_VALUE_MUTATION = """mutation createAttributeValue(- $attributeId: ID!, $name: String!) {+ $attributeId: ID!, $name: String!, $value: String) {attributeValueCreate(- attribute: $attributeId, input: {name: $name}) {+ attribute: $attributeId, input: {name: $name, value: $value}) {attributeErrors {fieldmessage@@ -38,6 +38,7 @@ CREATE_ATTRIBUTE_VALUE_MUTATION = """attribute {values {name+ value}}attributeValue {@@ -57,7 +58,8 @@ def test_create_attribute_value(query = CREATE_ATTRIBUTE_VALUE_MUTATIONattribute_id = graphene.Node.to_global_id("Attribute", attribute.id)name = "test name"- variables = {"name": name, "attributeId": attribute_id}+ value = "test value"+ variables = {"name": name, "value": value, "attributeId": attribute_id}# whenresponse = staff_api_client.post_graphql(@@ -73,6 +75,7 @@ def test_create_attribute_value(assert attr_data["name"] == nameassert attr_data["slug"] == slugify(name)assert name in [value["name"] for value in data["attribute"]["values"]]+ assert value in [value["value"] for value in data["attribute"]["values"]]def test_create_attribute_value_not_unique_name(diff --git a/saleor/graphql/attribute/types.py b/saleor/graphql/attribute/types.pyindex 01d1ad0704..ee84114b34 100644--- a/saleor/graphql/attribute/types.py+++ b/saleor/graphql/attribute/types.py@@ -23,6 +23,7 @@ color_pattern = re.compile(COLOR_PATTERN)class AttributeValue(CountableDjangoObjectType):name = graphene.String(description=AttributeValueDescriptions.NAME)slug = graphene.String(description=AttributeValueDescriptions.SLUG)+ value = graphene.String(description=AttributeValueDescriptions.VALUE)translation = TranslationField(AttributeValueTranslation, type_name="attribute value")diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex c754122668..925555a2ef 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -571,6 +571,7 @@ type AttributeValue implements Node {id: ID!name: Stringslug: String+ value: Stringtranslation(languageCode: LanguageCodeEnum!): AttributeValueTranslationinputType: AttributeInputTypeEnumreference: ID@@ -592,6 +593,7 @@ type AttributeValueCreate {input AttributeValueCreateInput {name: String!+ value: String}type AttributeValueDelete {