Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Allow filtering attribute values by ids (#9399)
Iga Karbowiak08b6645b4386
diff --git a/saleor/graphql/attribute/filters.py b/saleor/graphql/attribute/filters.pyindex 4ece4cd3ed..a2ebf93465 100644--- a/saleor/graphql/attribute/filters.py+++ b/saleor/graphql/attribute/filters.py@@ -61,6 +61,7 @@ def filter_attribute_type(qs, _, value):class AttributeValueFilter(django_filters.FilterSet):search = django_filters.CharFilter(method="filter_search")+ ids = GlobalIDMultipleChoiceFilter(field_name="id")class Meta:model = AttributeValuediff --git a/saleor/graphql/attribute/tests/queries/test_attribute_filter.py b/saleor/graphql/attribute/tests/queries/test_attribute_filter.pyindex 0808f4c521..ebb68430cd 100644--- a/saleor/graphql/attribute/tests/queries/test_attribute_filter.py+++ b/saleor/graphql/attribute/tests/queries/test_attribute_filter.py@@ -128,6 +128,29 @@ def test_filter_attributes_by_global_id_list(api_client, product_type_attribute_assert received_slugs == expected_slugs+def test_filter_attribute_values_by_global_id_list(+ api_client, attribute_choices_for_sorting+):+ # given+ values = attribute_choices_for_sorting.values.all()+ global_ids = [+ graphene.Node.to_global_id("AttributeValue", value.pk) for value in values[:2]+ ]+ variables = {"filters": {"ids": global_ids}}++ # when+ content = get_graphql_content(+ api_client.post_graphql(ATTRIBUTES_VALUE_FILTER_QUERY, variables)+ )++ # then+ expected_slugs = sorted([values[0].slug, values[1].slug])+ values = content["data"]["attributes"]["edges"][0]["node"]["choices"]["edges"]+ assert len(values) == 2+ received_slugs = sorted([value["node"]["slug"] for value in values])+ assert received_slugs == expected_slugs++def test_filter_attributes_in_category_invalid_category_id(user_api_client, product_list, weight_attribute, channel_USD):diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 9fd6f38c9d..7b39a8d06c 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -3257,6 +3257,7 @@ enum AttributeChoicesSortField {input AttributeValueFilterInput {search: String+ ids: [ID!]}type AttributeTranslation implements Node {