Skip to content

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

Add filter by slugs for choices #13076

rafiwts17d84f21f0e8
diff --git a/saleor/graphql/attribute/filters.py b/saleor/graphql/attribute/filters.py
index 945ed82326..c05b0eeb27 100644
--- a/saleor/graphql/attribute/filters.py
+++ b/saleor/graphql/attribute/filters.py
@@ -83,6 +83,7 @@ def filter_by_attribute_type(qs, _, value):
class AttributeValueFilter(django_filters.FilterSet):
search = django_filters.CharFilter(method="filter_search")
ids = GlobalIDMultipleChoiceFilter(field_name="id")
+ slugs = ListObjectTypeFilter(input_class=graphene.String, method=filter_slug_list)
class Meta:
model = AttributeValue
diff --git a/saleor/graphql/attribute/tests/queries/test_attribute_filter.py b/saleor/graphql/attribute/tests/queries/test_attribute_filter.py
index ebb68430cd..6003efc2c7 100644
--- a/saleor/graphql/attribute/tests/queries/test_attribute_filter.py
+++ b/saleor/graphql/attribute/tests/queries/test_attribute_filter.py
@@ -73,6 +73,23 @@ def test_search_attributes_value(
assert values[0]["node"]["slug"] == filter_value
+ "filter_by, attributes_count",
+ [({"slugs": ["red", "blue"]}, 2), ({"slugs": ["red"]}, 1), ({"slugs": []}, 2)],
+)
+def test_atribute_values_with_filtering_slugs(
+ filter_by, api_client, attributes_count, color_attribute, size_attribute
+):
+ variables = {"filters": filter_by}
+
+ attributes = get_graphql_content(
+ api_client.post_graphql(ATTRIBUTES_VALUE_FILTER_QUERY, variables)
+ )["data"]["attributes"]
+
+ slugs = attributes["edges"][0]["node"]["choices"]["edges"]
+ assert len(slugs) == attributes_count
+
+
def test_filter_attributes_if_filterable_in_dashboard(
api_client, color_attribute, size_attribute
):
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 2800a70a5e..737230dd14 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -6344,6 +6344,7 @@ enum AttributeChoicesSortField @doc(category: "Attributes") {
input AttributeValueFilterInput @doc(category: "Attributes") {
search: String
ids: [ID!]
+ slugs: [String!]
}
type AttributeTranslation implements Node @doc(category: "Attributes") {