Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Added capability to filter attributes per global ID
NyanKiyoshica8111bb5826
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d790056572..4bf78a3d9e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -51,6 +51,7 @@ All notable, unreleased changes to this project will be documented in this file.- Fix bulk actions - #4618 by @dominik-zeglen- Remove dashboard 2.0 files - #4631 by @dominik-zeglen- Refactoring of password recovery system - #4617 by @fowczarek+- Added capability to filter attributes per global ID - #4640 by @NyanKiyoshi.## 2.8.0diff --git a/saleor/graphql/product/filters.py b/saleor/graphql/product/filters.pyindex 7b21548ce5..84e9c7fb4a 100644--- a/saleor/graphql/product/filters.py+++ b/saleor/graphql/product/filters.py@@ -223,6 +223,7 @@ class ProductTypeFilter(django_filters.FilterSet):class AttributeFilter(django_filters.FilterSet):# Search by attribute name and slugsearch = django_filters.CharFilter(method=filter_attributes_search)+ ids = GlobalIDMultipleChoiceFilter(field_name="id")class Meta:model = Attributediff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 50b15e1667..a17cae798d 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -228,6 +228,7 @@ input AttributeFilterInput {filterableInDashboard: BooleanavailableInGrid: Booleansearch: String+ ids: [ID]}input AttributeInput {diff --git a/tests/api/test_attributes.py b/tests/api/test_attributes.pyindex eb7621de98..b30122bed4 100644--- a/tests/api/test_attributes.py+++ b/tests/api/test_attributes.py@@ -1755,6 +1755,27 @@ def test_filter_attributes_if_available_in_grid(assert attributes[0]["node"]["slug"] == "size"+def test_filter_attributes_by_global_id_list(api_client, attribute_list):+ global_ids = [+ graphene.Node.to_global_id("Attribute", attribute.pk)+ for attribute in attribute_list[:2]+ ]+ variables = {"filters": {"ids": global_ids}}++ expected_slugs = sorted([attribute_list[0].slug, attribute_list[1].slug])++ attributes = get_graphql_content(+ api_client.post_graphql(ATTRIBUTES_FILTER_QUERY, variables)+ )["data"]["attributes"]["edges"]++ assert len(attributes) == 2+ received_slugs = sorted(+ [attributes[0]["node"]["slug"], attributes[1]["node"]["slug"]]+ )++ assert received_slugs == expected_slugs++ATTRIBUTES_SORT_QUERY = """query($sortBy: AttributeSortingInput) {attributes(first: 10, sortBy: $sortBy) {