Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add filtering by Product IDs to `products` query
Grzegorz Derdake725a9f1da8c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fd62da9667..1d8b78b794 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -24,6 +24,7 @@ All notable, unreleased changes to this project will be documented in this file.- Allow product variants to be sortable - #6138 by @tomaszszymanski129- Staff with only manage_orders should be able to query all stock related date. - #6139 by @fowczarek- Add filtering to `ProductVariants` query and option to fetch variant by sku in `ProductVariant` query - #6190 by @fowczarek+- Add filtering by Product IDs to `products` query - #6224 by @GrzegorzDerdak### Breaking Changesdiff --git a/saleor/graphql/product/filters.py b/saleor/graphql/product/filters.pyindex 3bd83dbc3f..23a03e54f8 100644--- a/saleor/graphql/product/filters.py+++ b/saleor/graphql/product/filters.py@@ -326,6 +326,7 @@ class ProductFilter(django_filters.FilterSet):product_types = GlobalIDMultipleChoiceFilter(field_name="product_type")stocks = ObjectTypeFilter(input_class=ProductStockFilterInput, method=filter_stocks)search = django_filters.CharFilter(method=filter_search)+ ids = GlobalIDMultipleChoiceFilter(field_name="id")class Meta:model = Productdiff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.pyindex ad54a185c4..fbfb76246a 100644--- a/saleor/graphql/product/tests/test_product.py+++ b/saleor/graphql/product/tests/test_product.py@@ -950,6 +950,21 @@ def test_products_query_with_filter_stocks(assert {node["node"]["id"] for node in products_data} == product_ids+def test_query_products_query_with_filter_ids(+ staff_api_client, product, query_products_with_filter+):+ product_global_id = graphene.Node.to_global_id("Product", product.id)+ variables = {"filter": {"ids": [product_global_id]}}+ response = staff_api_client.post_graphql(+ query_products_with_filter, variables, check_no_permissions=False+ )+ content = get_graphql_content(response)+ products_data = content["data"]["products"]["edges"]++ assert len(products_data) == 1+ assert products_data[0]["node"]["id"] == product_global_id++def test_query_product_image_by_id(user_api_client, product_with_image):image = product_with_image.images.first()query = """diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 767bcf4424..52e1c590d5 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -3791,6 +3791,7 @@ input ProductFilterInput {price: PriceRangeInputminimalPrice: PriceRangeInputproductTypes: [ID]+ ids: [ID]}type ProductImage implements Node {