Skip to content

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

Deprecate query args (#7806)

Marcin Gębala76682ecaede7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b9fbea41cb..7c92542dce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -131,6 +131,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Add `withChoices` flag for Attribute type - #7733 by @dexon44
- Drop assigning cheapest shipping method in checkout - #7767 by @maarcingebala
- Add `product_id`, `product_variant_id`, `attribute_id` and `page_id` when it's possible for `AttributeValue` translations webhook. - #7783 by @fowczarek
+- Deprecate `query` argument in `sales` and `vouchers` queries - #7806 by @maarcingebala
### Breaking
- Multichannel MVP: Multicurrency - #6242 by @fowczarek @d-wysocki
diff --git a/saleor/graphql/core/types/filter_input.py b/saleor/graphql/core/types/filter_input.py
index 4cfcc03e30..f595d50d1d 100644
--- a/saleor/graphql/core/types/filter_input.py
+++ b/saleor/graphql/core/types/filter_input.py
@@ -68,7 +68,7 @@ class ChannelFilterInputObjectType(FilterInputObjectType):
channel = Argument(
String,
description=(
- "Specifies the channel by which the data should be filtered."
+ "Specifies the channel by which the data should be filtered. "
"DEPRECATED: Will be removed in Saleor 4.0."
"Use root-level channel argument instead."
),
diff --git a/saleor/graphql/core/types/sort_input.py b/saleor/graphql/core/types/sort_input.py
index e2159a3b3f..d104903b8f 100644
--- a/saleor/graphql/core/types/sort_input.py
+++ b/saleor/graphql/core/types/sort_input.py
@@ -41,7 +41,7 @@ class ChannelSortInputObjectType(SortInputObjectType):
channel = graphene.Argument(
graphene.String,
description=(
- "Specifies the channel in which to sort the data."
+ "Specifies the channel in which to sort the data. "
"DEPRECATED: Will be removed in Saleor 4.0."
"Use root-level channel argument instead."
),
diff --git a/saleor/graphql/discount/resolvers.py b/saleor/graphql/discount/resolvers.py
index 314b95415c..feb6b204da 100644
--- a/saleor/graphql/discount/resolvers.py
+++ b/saleor/graphql/discount/resolvers.py
@@ -1,8 +1,6 @@
from ...discount import models
from ..channel import ChannelContext, ChannelQsContext
-
-VOUCHER_SEARCH_FIELDS = ("name", "code")
-SALE_SEARCH_FIELDS = ("name", "value", "type")
+from .filters import filter_sale_search, filter_voucher_search
def resolve_voucher(id, channel):
@@ -10,10 +8,15 @@ def resolve_voucher(id, channel):
return ChannelContext(node=sale, channel_slug=channel) if sale else None
-def resolve_vouchers(info, channel_slug, **_kwargs) -> ChannelQsContext:
+def resolve_vouchers(info, channel_slug, **kwargs) -> ChannelQsContext:
qs = models.Voucher.objects.all()
if channel_slug:
qs = qs.filter(channel_listings__channel__slug=channel_slug)
+
+ # DEPRECATED: remove filtering by `query` argument when it's removed from the schema
+ if query := kwargs.get("query"):
+ qs = filter_voucher_search(qs, None, query)
+
return ChannelQsContext(qs=qs, channel_slug=channel_slug)
@@ -22,8 +25,13 @@ def resolve_sale(id, channel):
return ChannelContext(node=sale, channel_slug=channel) if sale else None
-def resolve_sales(info, channel_slug, **_kwargs) -> ChannelQsContext:
+def resolve_sales(info, channel_slug, **kwargs) -> ChannelQsContext:
qs = models.Sale.objects.all()
if channel_slug:
qs = qs.filter(channel_listings__channel__slug=channel_slug)
+
+ # DEPRECATED: remove filtering by `query` argument when it's removed from the schema
+ if query := kwargs.get("query"):
+ qs = filter_sale_search(qs, None, query)
+
return ChannelQsContext(qs=qs, channel_slug=channel_slug)
diff --git a/saleor/graphql/discount/schema.py b/saleor/graphql/discount/schema.py
index 0c58d03c38..a382ff1d03 100644
--- a/saleor/graphql/discount/schema.py
+++ b/saleor/graphql/discount/schema.py
@@ -50,7 +50,12 @@ class DiscountQueries(graphene.ObjectType):
Sale,
filter=SaleFilterInput(description="Filtering options for sales."),
sort_by=SaleSortingInput(description="Sort sales."),
- query=graphene.String(description="Search sales by name, value or type."),
+ query=graphene.String(
+ description=(
+ "Search sales by name, value or type. DEPRECATED: Will be removed in "
+ "Saleor 4.0. Use `filter.search` input instead."
+ )
+ ),
channel=graphene.String(
description="Slug of a channel for which the data should be returned."
),
@@ -70,7 +75,12 @@ class DiscountQueries(graphene.ObjectType):
Voucher,
filter=VoucherFilterInput(description="Filtering options for vouchers."),
sort_by=VoucherSortingInput(description="Sort voucher."),
- query=graphene.String(description="Search vouchers by name or code."),
+ query=graphene.String(
+ description=(
+ "Search vouchers by name or code. DEPRECATED: Will be removed in "
+ "Saleor 4.0. Use `filter.search` input instead."
+ )
+ ),
channel=graphene.String(
description="Slug of a channel for which the data should be returned."
),
diff --git a/saleor/graphql/discount/tests/deprecated/test_discount.py b/saleor/graphql/discount/tests/deprecated/test_discount.py
index 8355c1de10..41ee22a04b 100644
--- a/saleor/graphql/discount/tests/deprecated/test_discount.py
+++ b/saleor/graphql/discount/tests/deprecated/test_discount.py
@@ -1,15 +1,12 @@
import warnings
from .....channel.utils import DEPRECATION_WARNING_MESSAGE
+from .....discount.models import Sale, Voucher
from ....tests.utils import get_graphql_content
QUERY_SALES_WITH_SORTING_AND_FILTERING = """
- query (
- $sortBy: SaleSortingInput
- ){
- sales (
- first: 10, sortBy: $sortBy
- ) {
+ query($sortBy: SaleSortingInput){
+ sales (first: 10, sortBy: $sortBy) {
edges {
node {
name
@@ -84,3 +81,53 @@ def test_query_vouchers_with_sort(
assert any(
[str(warning.message) == DEPRECATION_WARNING_MESSAGE for warning in warns]
)
+
+
+def test_filter_sales_by_query(staff_api_client, permission_manage_discounts):
+ sales = Sale.objects.bulk_create([Sale(name="Spanish"), Sale(name="Inquisition")])
+ sale = sales[1]
+
+ query = """
+ query Sales($query: String) {
+ sales(first:5, query: $query) {
+ edges {
+ node {
+ name
+ }
+ }
+ }
+ }
+ """
+
+ staff_api_client.user.user_permissions.add(permission_manage_discounts)
+ response = staff_api_client.post_graphql(query, {"query": sale.name})
+ content = get_graphql_content(response)
+ assert content["data"]["sales"]["edges"][0]["node"]["name"] == sale.name
+
+
+def test_filter_vouchers_by_query(staff_api_client, permission_manage_discounts):
+ vouchers = Voucher.objects.bulk_create(
+ [
+ Voucher(code="code1", name="Spanish"),
+ Voucher(code="code2", name="Inquisition"),
+ ]
+ )
+ voucher = vouchers[1]
+
+ query = """
+ query Vouchers($query: String) {
+ vouchers(first:5, query: $query) {
+ edges {
+ node {
+ name
+ code
+ }
+ }
+ }
+ }
+ """
+
+ staff_api_client.user.user_permissions.add(permission_manage_discounts)
+ response = staff_api_client.post_graphql(query, {"query": voucher.name})
+ content = get_graphql_content(response)
+ assert content["data"]["vouchers"]["edges"][0]["node"]["code"] == voucher.code
diff --git a/saleor/graphql/product/bulk_mutations/products.py b/saleor/graphql/product/bulk_mutations/products.py
index 8576b05f99..a5ec0ee84c 100644
--- a/saleor/graphql/product/bulk_mutations/products.py
+++ b/saleor/graphql/product/bulk_mutations/products.py
@@ -182,7 +182,7 @@ class BulkAttributeValueInput(InputObjectType):
boolean = graphene.Boolean(
required=False,
description=(
- "The boolean value of an attribute to resolve."
+ "The boolean value of an attribute to resolve. "
"If the passed value is non-existent, it will be created."
),
)