Skip to content

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

Deprecate all `filter` arguments in case `where` is available (#17854)

Iga Karbowiakb513608cf1cc
diff --git a/saleor/graphql/attribute/schema.py b/saleor/graphql/attribute/schema.py
index 748d54ad8e..46f3dfaa41 100644
--- a/saleor/graphql/attribute/schema.py
+++ b/saleor/graphql/attribute/schema.py
@@ -3,6 +3,7 @@ import graphene
from ...attribute import models
from ..core import ResolveInfo
from ..core.connection import create_connection_slice, filter_connection_queryset
+from ..core.descriptions import DEPRECATED_IN_3X_INPUT
from ..core.doc_category import DOC_CATEGORY_ATTRIBUTES
from ..core.fields import BaseField, FilterConnectionField
from ..core.utils.resolvers import resolve_by_global_id_slug_or_ext_ref
@@ -34,8 +35,15 @@ class AttributeQueries(graphene.ObjectType):
attributes = FilterConnectionField(
AttributeCountableConnection,
description="List of the shop's attributes.",
- filter=AttributeFilterInput(description="Filtering options for attributes."),
- where=AttributeWhereInput(description="Filtering options for attributes."),
+ filter=AttributeFilterInput(
+ description=(
+ f"Filtering options for attributes. {DEPRECATED_IN_3X_INPUT} "
+ "Use `where` filter instead."
+ )
+ ),
+ where=AttributeWhereInput(
+ description="Where filtering options for attributes."
+ ),
search=graphene.String(description="Search attributes."),
sort_by=AttributeSortingInput(description="Sorting options for attributes."),
channel=graphene.String(
diff --git a/saleor/graphql/discount/schema.py b/saleor/graphql/discount/schema.py
index b41379ddec..a224f4c704 100644
--- a/saleor/graphql/discount/schema.py
+++ b/saleor/graphql/discount/schema.py
@@ -151,7 +151,9 @@ class DiscountQueries(graphene.ObjectType):
)
promotions = FilterConnectionField(
PromotionCountableConnection,
- where=PromotionWhereInput(description="Where filtering options."),
+ where=PromotionWhereInput(
+ description="Where filtering options for promotions."
+ ),
sort_by=PromotionSortingInput(description="Sort promotions."),
description="List of the promotions.",
permissions=[DiscountPermissions.MANAGE_DISCOUNTS],
diff --git a/saleor/graphql/order/schema.py b/saleor/graphql/order/schema.py
index 0baf876320..c5a88ba2d9 100644
--- a/saleor/graphql/order/schema.py
+++ b/saleor/graphql/order/schema.py
@@ -13,7 +13,11 @@ from ..core.connection import (
filter_connection_queryset,
)
from ..core.context import get_database_connection_name
-from ..core.descriptions import ADDED_IN_322, DEFAULT_DEPRECATION_REASON
+from ..core.descriptions import (
+ ADDED_IN_322,
+ DEFAULT_DEPRECATION_REASON,
+ DEPRECATED_IN_3X_INPUT,
+)
from ..core.doc_category import DOC_CATEGORY_ORDERS
from ..core.enums import ReportingPeriod
from ..core.fields import (
@@ -125,7 +129,12 @@ class OrderQueries(graphene.ObjectType):
orders = FilterConnectionField(
OrderCountableConnection,
sort_by=OrderSortingInput(description="Sort orders."),
- filter=OrderFilterInput(description="Filtering options for orders."),
+ filter=OrderFilterInput(
+ description=(
+ f"Filtering options for orders. {DEPRECATED_IN_3X_INPUT} "
+ "Use `where` filter instead."
+ )
+ ),
where=OrderWhereInput(
description="Where filtering options for orders." + ADDED_IN_322
),
diff --git a/saleor/graphql/page/tests/queries/test_page_type.py b/saleor/graphql/page/tests/queries/test_page_type.py
index 7c93a7e715..0fab900fa7 100644
--- a/saleor/graphql/page/tests/queries/test_page_type.py
+++ b/saleor/graphql/page/tests/queries/test_page_type.py
@@ -9,7 +9,8 @@ from ....tests.utils import (
PAGE_TYPE_QUERY = """
query PageType(
- $id: ID!, $filters: AttributeFilterInput, $where: AttributeWhereInput
+ $id: ID!, $filters: AttributeFilterInput, $where: AttributeWhereInput,
+ $search: String
) {
pageType(id: $id) {
id
@@ -19,7 +20,7 @@ PAGE_TYPE_QUERY = """
attributes {
slug
}
- availableAttributes(first: 10, filter: $filters, where: $where) {
+ availableAttributes(first: 10, filter: $filters, where: $where, search: $search) {
edges {
node {
slug
@@ -239,6 +240,38 @@ def test_page_type_query_where_filter_unassigned_attributes(
assert available_attributes[0]["node"]["slug"] == expected_attribute.slug
+def test_page_type_query_search_unassigned_attributes(
+ staff_api_client,
+ page_type,
+ permission_manage_pages,
+ page_type_attribute_list,
+):
+ # given
+ staff_user = staff_api_client.user
+ staff_user.user_permissions.add(permission_manage_pages)
+ expected_attr = page_type_attribute_list[0]
+
+ variables = {
+ "id": graphene.Node.to_global_id("PageType", page_type.pk),
+ "search": expected_attr.name,
+ }
+
+ # when
+ response = staff_api_client.post_graphql(PAGE_TYPE_QUERY, variables)
+
+ # then
+ content = get_graphql_content(response)
+ page_type_data = content["data"]["pageType"]
+
+ assert page_type_data["slug"] == page_type.slug
+ assert {attr["slug"] for attr in page_type_data["attributes"]} == {
+ attr.slug for attr in page_type.page_attributes.all()
+ }
+ available_attributes = page_type_data["availableAttributes"]["edges"]
+ assert len(available_attributes) == 1
+ assert available_attributes[0]["node"]["slug"] == expected_attr.slug
+
+
def test_page_type_query_no_pages(
staff_api_client,
page_type,
diff --git a/saleor/graphql/page/types.py b/saleor/graphql/page/types.py
index 5126143aaa..054d7c4bf8 100644
--- a/saleor/graphql/page/types.py
+++ b/saleor/graphql/page/types.py
@@ -3,7 +3,11 @@ import graphene
from ...attribute import models as attribute_models
from ...page import models
from ...permission.enums import PagePermissions, PageTypePermissions
-from ..attribute.filters import AttributeFilterInput, AttributeWhereInput
+from ..attribute.filters import (
+ AttributeFilterInput,
+ AttributeWhereInput,
+ filter_attribute_search,
+)
from ..attribute.types import Attribute, AttributeCountableConnection, SelectedAttribute
from ..core import ResolveInfo
from ..core.connection import (
@@ -12,7 +16,7 @@ from ..core.connection import (
filter_connection_queryset,
)
from ..core.context import get_database_connection_name
-from ..core.descriptions import RICH_CONTENT
+from ..core.descriptions import DEPRECATED_IN_3X_INPUT, RICH_CONTENT
from ..core.doc_category import DOC_CATEGORY_PAGES
from ..core.federation import federated_entity, resolve_federation_references
from ..core.fields import FilterConnectionField, JSONString, PermissionsField
@@ -44,8 +48,14 @@ class PageType(ModelObjectType[models.PageType]):
)
available_attributes = FilterConnectionField(
AttributeCountableConnection,
- filter=AttributeFilterInput(),
- where=AttributeWhereInput(),
+ filter=AttributeFilterInput(
+ description="Filtering options for attributes. "
+ f"{DEPRECATED_IN_3X_INPUT} Use `where` filter instead."
+ ),
+ where=AttributeWhereInput(
+ description="Where filtering options for attributes."
+ ),
+ search=graphene.String(description="Search attributes."),
description="Attributes that can be assigned to the page type.",
permissions=[
PagePermissions.MANAGE_PAGES,
@@ -88,7 +98,7 @@ class PageType(ModelObjectType[models.PageType]):
@staticmethod
def resolve_available_attributes(
- root: models.PageType, info: ResolveInfo, **kwargs
+ root: models.PageType, info: ResolveInfo, search=None, **kwargs
):
qs = attribute_models.Attribute.objects.get_unassigned_page_type_attributes(
root.pk
@@ -96,6 +106,8 @@ class PageType(ModelObjectType[models.PageType]):
qs = filter_connection_queryset(
qs, kwargs, info.context, allow_replica=info.context.allow_replica
)
+ if search:
+ qs = filter_attribute_search(qs, None, search)
return create_connection_slice(qs, info, kwargs, AttributeCountableConnection)
@staticmethod
diff --git a/saleor/graphql/product/schema.py b/saleor/graphql/product/schema.py
index db82e41ef7..58a3185f03 100644
--- a/saleor/graphql/product/schema.py
+++ b/saleor/graphql/product/schema.py
@@ -13,6 +13,7 @@ from ..core.connection import create_connection_slice, filter_connection_queryse
from ..core.descriptions import (
ADDED_IN_321,
DEFAULT_DEPRECATION_REASON,
+ DEPRECATED_IN_3X_INPUT,
)
from ..core.doc_category import DOC_CATEGORY_PRODUCTS
from ..core.enums import LanguageCodeEnum, ReportingPeriod
@@ -173,7 +174,7 @@ class ProductQueries(graphene.ObjectType):
categories = FilterConnectionField(
CategoryCountableConnection,
filter=CategoryFilterInput(description="Filtering options for categories."),
- where=CategoryWhereInput(description="Where filtering options."),
+ where=CategoryWhereInput(description="Where filtering options for categories."),
sort_by=CategorySortingInput(description="Sort categories."),
level=graphene.Argument(
graphene.Int,
@@ -220,7 +221,9 @@ class ProductQueries(graphene.ObjectType):
collections = FilterConnectionField(
CollectionCountableConnection,
filter=CollectionFilterInput(description="Filtering options for collections."),
- where=CollectionWhereInput(description="Where filtering options."),
+ where=CollectionWhereInput(
+ description="Where filtering options for collections."
+ ),
sort_by=CollectionSortingInput(description="Sort collections."),
description=(
"List of the shop's collections. Requires one of the following permissions "
@@ -259,8 +262,13 @@ class ProductQueries(graphene.ObjectType):
)
products = FilterConnectionField(
ProductCountableConnection,
- filter=ProductFilterInput(description="Filtering options for products."),
- where=ProductWhereInput(description="Where filtering options."),
+ filter=ProductFilterInput(
+ description=(
+ f"Filtering options for products. {DEPRECATED_IN_3X_INPUT} "
+ "Use `where` filter instead."
+ )
+ ),
+ where=ProductWhereInput(description="Where filtering options for products."),
sort_by=ProductOrder(description="Sort products."),
search=graphene.String(description="Search products."),
channel=graphene.String(
@@ -323,7 +331,9 @@ class ProductQueries(graphene.ObjectType):
filter=ProductVariantFilterInput(
description="Filtering options for product variant."
),
- where=ProductVariantWhereInput(description="Where filtering options."),
+ where=ProductVariantWhereInput(
+ description="Where filtering options for product variants."
+ ),
sort_by=ProductVariantSortingInput(description="Sort products variants."),
description=(
"List of product variants. Requires one of the following permissions to "
diff --git a/saleor/graphql/product/tests/queries/test_product_type_query.py b/saleor/graphql/product/tests/queries/test_product_type_query.py
index 3094c6f1d9..81e9e3e622 100644
--- a/saleor/graphql/product/tests/queries/test_product_type_query.py
+++ b/saleor/graphql/product/tests/queries/test_product_type_query.py
@@ -355,10 +355,11 @@ def test_product_type_query_only_assigned_variant_selections_value_set(
QUERY_AVAILABLE_ATTRIBUTES = """
query(
- $productTypeId:ID!, $filters: AttributeFilterInput, $where: AttributeWhereInput
+ $productTypeId:ID!, $filters: AttributeFilterInput, $where: AttributeWhereInput,
+ $search: String
) {
productType(id: $productTypeId) {
- availableAttributes(first: 10, filter: $filters, where: $where) {
+ availableAttributes(first: 10, filter: $filters, where: $where, search: $search) {
edges {
node {
id
@@ -497,6 +498,34 @@ def test_product_type_where_filter_unassigned_attributes(
assert attribute_id == str(expected_attribute.pk)
+def test_product_type_search_unassigned_attributes(
+ staff_api_client, permission_manage_products, product_type_attribute_list
+):
+ # given
+ expected_attribute = product_type_attribute_list[0]
+ query = QUERY_AVAILABLE_ATTRIBUTES
+ product_type = ProductType.objects.create(
+ name="Empty Type", kind=ProductTypeKind.NORMAL
+ )
+ product_type_id = graphene.Node.to_global_id("ProductType", product_type.pk)
+ filters = {"search": expected_attribute.name}
+
+ # when
+ found_attributes = get_graphql_content(
+ staff_api_client.post_graphql(
+ query,
+ {"productTypeId": product_type_id, "filters": filters},
+ permissions=[permission_manage_products],
+ )
+ )["data"]["productType"]["availableAttributes"]["edges"]
+
+ # then
+ assert len(found_attributes) == 1
+
+ _, attribute_id = graphene.Node.from_global_id(found_attributes[0]["node"]["id"])
+ assert attribute_id == str(expected_attribute.pk)
+
+
QUERY_PRODUCT_TYPE = """
query ($id: ID!){
productType(
diff --git a/saleor/graphql/product/tests/test_category_filtering.py b/saleor/graphql/product/tests/test_category_filtering.py
index 32015fb126..ab52072d43 100644
--- a/saleor/graphql/product/tests/test_category_filtering.py
+++ b/saleor/graphql/product/tests/test_category_filtering.py
@@ -157,11 +157,19 @@ def test_order_query_with_filter_updated_at(
GET_FILTERED_PRODUCTS_CATEGORY_QUERY = """
-query ($id: ID!, $channel: String, $filters: ProductFilterInput) {
+query (
+ $id: ID!,
+ $channel: String,
+ $filters: ProductFilterInput,
+ $where: ProductWhereInput,
+ $search: String,
+) {
category(id: $id) {
id
name
- products(first: 5, channel: $channel, filter: $filters) {
+ products(
+ first: 5, channel: $channel, filter: $filters, where: $where, search: $search
+ ) {
edges {
node {
id
@@ -593,6 +601,102 @@ def test_category_filter_products_by_ids(
assert [node["node"]["id"] for node in products] == product_ids
+ ("is_published", "count", "indexes_of_products_in_result"),
+ [
+ (True, 2, [1, 2]),
+ (False, 1, [0]),
+ ],
+)
+def test_category_where_products_by_is_published(
+ is_published,
+ count,
+ indexes_of_products_in_result,
+ staff_api_client,
+ permission_manage_products,
+ category,
+ product_list_published,
+ channel_USD,
+):
+ # given
+ ProductChannelListing.objects.filter(
+ product=product_list_published[0],
+ ).update(is_published=False)
+
+ product_ids = [
+ graphene.Node.to_global_id("Product", product_list_published[index].pk)
+ for index in indexes_of_products_in_result
+ ]
+
+ variables = {
+ "id": graphene.Node.to_global_id("Category", category.pk),
+ "channel": channel_USD.slug,
+ "where": {"isPublished": is_published},
+ }
+
+ # when
+ response = staff_api_client.post_graphql(
+ GET_FILTERED_PRODUCTS_CATEGORY_QUERY,
+ variables,
+ permissions=[permission_manage_products],
+ check_no_permissions=False,
+ )
+
+ # then
+ content = get_graphql_content(response)
+ products = content["data"]["category"]["products"]["edges"]
+ assert len(products) == count
+ assert [product["node"]["id"] for product in products] == product_ids
+
+
+ ("is_published", "count", "indexes_of_products_in_result"),
+ [
+ (True, 1, [1]),
+ (False, 0, []),
+ ],
+)
+def test_category_search_products_by_sku(
+ is_published,
+ count,
+ indexes_of_products_in_result,
+ user_api_client,
+ category,
+ product_with_two_variants,
+ product_with_default_variant,
+ channel_USD,
+):
+ # given
+ products = [product_with_two_variants, product_with_default_variant]
+
+ ProductChannelListing.objects.filter(
+ product=product_with_default_variant, channel=channel_USD
+ ).update(is_published=is_published)
+
+ variables = {
+ "id": graphene.Node.to_global_id("Category", category.pk),
+ "channel": channel_USD.slug,
+ "search": "1234",
+ }
+
+ # when
+ response = user_api_client.post_graphql(
+ GET_FILTERED_PRODUCTS_CATEGORY_QUERY,
+ variables,
+ )
+
+ # then
+ content = get_graphql_content(response)
+ products_result = content["data"]["category"]["products"]["edges"]
+ product_ids = {
+ graphene.Node.to_global_id("Product", products[index].pk)
+ for index in indexes_of_products_in_result
+ }
+
+ assert len(products_result) == count
+ assert {node["node"]["id"] for node in products_result} == product_ids
+
+
GET_SORTED_PRODUCTS_CATEGORY_QUERY = """
query (
$id: ID!,
diff --git a/saleor/graphql/product/tests/test_collection.py b/saleor/graphql/product/tests/test_collection.py
index b79534d6d6..c07fd041e2 100644
--- a/saleor/graphql/product/tests/test_collection.py
+++ b/saleor/graphql/product/tests/test_collection.py
@@ -329,9 +329,10 @@ query CollectionProducts(
$channel: String,
$filters: ProductFilterInput,
$where: ProductWhereInput,
+ $search: String,
) {
collection(id: $id, channel: $channel) {
- products(first: 10, filter: $filters, where: $where) {
+ products(first: 10, filter: $filters, where: $where, search: $search) {
edges {
node {
id
@@ -498,6 +499,33 @@ def test_filter_where_collection_products(
)
+def test_search_collection_products(
+ user_api_client, product_list, published_collection, channel_USD, channel_PLN
+):
+ # given
+ query = GET_FILTERED_PRODUCTS_COLLECTION_QUERY
+
+ for product in product_list:
+ published_collection.products.add(product)
+
+ product = product_list[0]
+
+ variables = {
+ "id": graphene.Node.to_global_id("Collection", published_collection.pk),
+ "search": product.name,
+ "channel": channel_USD.slug,
+ }
+
+ # when
+ response = user_api_client.post_graphql(query, variables)
+
+ # then
+ content = get_graphql_content(response)
+ product_data = content["data"]["collection"]["products"]["edges"][0]["node"]
+
+ assert product_data["id"] == graphene.Node.to_global_id("Product", product.pk)
+
+
CREATE_COLLECTION_MUTATION = """
mutation createCollection(
$name: String!, $slug: String,
diff --git a/saleor/graphql/product/types/categories.py b/saleor/graphql/product/types/categories.py
index b8020cc148..c801fa07aa 100644
--- a/saleor/graphql/product/types/categories.py
+++ b/saleor/graphql/product/types/categories.py
@@ -5,6 +5,7 @@ from promise import Promise
from ....permission.utils import has_one_of_permissions
from ....product import models
from ....product.models import ALL_PRODUCTS_PERMISSIONS
+from ....product.search import search_products
from ....thumbnail.utils import (
get_image_or_proxy_url,
get_thumbnail_format,
@@ -63,9 +64,14 @@ class Category(ModelObjectType[models.Category]):
)
products = FilterConnectionField(
ProductCountableConnection,
- filter=ProductFilterInput(description="Filtering options for products."),
- where=ProductWhereInput(description="Filtering options for products."),
+ filter=ProductFilterInput(
+ description=(
+ "Filtering options for products. {DEPRECATED_IN_3X_INPUT} Use `where` filter instead."
+ )
+ ),
+ where=ProductWhereInput(description="Where filtering options for products."),
sort_by=ProductOrder(description="Sort products."),
+ search=graphene.String(description="Search products."),
channel=graphene.String(
description="Slug of a channel for which the data should be returned."
),
@@ -160,6 +166,7 @@ class Category(ModelObjectType[models.Category]):
@staticmethod
def resolve_products(root: models.Category, info, *, channel=None, **kwargs):
+ search = kwargs.get("search")
requestor = get_user_or_app_from_context(info.context)
has_required_permissions = has_one_of_permissions(
requestor, ALL_PRODUCTS_PERMISSIONS
@@ -185,13 +192,21 @@ class Category(ModelObjectType[models.Category]):
if channel_obj and has_required_permissions:
qs = qs.filter(channel_listings__channel_id=channel_obj.id)
qs = qs.filter(category__in=tree)
- qs = ChannelQsContext(qs=qs, channel_slug=channel)
+
+ if search:
+ channel_qs = ChannelQsContext(
+ qs=search_products(qs, search), channel_slug=channel
+ )
+ else:
+ channel_qs = ChannelQsContext(qs=qs, channel_slug=channel)
kwargs["channel"] = channel
- qs = filter_connection_queryset(
- qs, kwargs, allow_replica=info.context.allow_replica
+ channel_qs = filter_connection_queryset(
+ channel_qs, kwargs, allow_replica=info.context.allow_replica
+ )
+ return create_connection_slice(
+ channel_qs, info, kwargs, ProductCountableConnection
)
- return create_connection_slice(qs, info, kwargs, ProductCountableConnection)
if channel:
return (
diff --git a/saleor/graphql/product/types/collections.py b/saleor/graphql/product/types/collections.py
index 047e7a6dde..db7b11ece7 100644
--- a/saleor/graphql/product/types/collections.py
+++ b/saleor/graphql/product/types/collections.py
@@ -22,7 +22,7 @@ from ...core.connection import (
filter_connection_queryset,
)
from ...core.context import get_database_connection_name
-from ...core.descriptions import RICH_CONTENT
+from ...core.descriptions import DEPRECATED_IN_3X_INPUT, RICH_CONTENT
from ...core.doc_category import DOC_CATEGORY_PRODUCTS
from ...core.federation import federated_entity
from ...core.fields import FilterConnectionField, JSONString, PermissionsField
@@ -65,8 +65,14 @@ class Collection(ChannelContextType[models.Collection]):
)
products = FilterConnectionField(
ProductCountableConnection,
- filter=ProductFilterInput(description="Filtering options for products."),
- where=ProductWhereInput(description="Filtering options for products."),
+ filter=ProductFilterInput(
+ description=(
+ f"Filtering options for products. {DEPRECATED_IN_3X_INPUT} "
+ "Use `where` filter instead."
+ )
+ ),
+ where=ProductWhereInput(description="Where filtering options for products."),
+ search=graphene.String(description="Search products."),
sort_by=ProductOrder(description="Sort products."),
description="List of products in this collection.",
)
@@ -141,7 +147,7 @@ class Collection(ChannelContextType[models.Collection]):
if search:
qs = ChannelQsContext(
- qs=search_products(qs.qs, search), channel_slug=root.channel_slug
+ qs=search_products(qs, search), channel_slug=root.channel_slug
)
else:
qs = ChannelQsContext(qs=qs, channel_slug=root.channel_slug)
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index ecc2ff245c..e96d9dbdc4 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -37,7 +37,11 @@ from ....thumbnail.utils import (
from ....warehouse.reservations import is_reservation_enabled
from ...account import types as account_types
from ...account.enums import CountryCodeEnum
-from ...attribute.filters import AttributeFilterInput, AttributeWhereInput
+from ...attribute.filters import (
+ AttributeFilterInput,
+ AttributeWhereInput,
+ filter_attribute_search,
+)
from ...attribute.resolvers import resolve_attributes
from ...attribute.types import (
AssignedVariantAttribute,
@@ -958,7 +962,9 @@ class Product(ChannelContextType[models.Product]):
filter=ProductVariantFilterInput(
description="Filtering options for product variant."
),
- where=ProductVariantWhereInput(description="Where filtering options."),
+ where=ProductVariantWhereInput(
+ description="Where filtering options for product variants."
+ ),
sort_by=ProductVariantSortingInput(description="Sort products variants."),
description=(
"List of variants for the product. Requires the following permissions to "
@@ -1733,8 +1739,16 @@ class ProductType(ModelObjectType[models.ProductType]):
)
available_attributes = FilterConnectionField(
AttributeCountableConnection,
- filter=AttributeFilterInput(),
- where=AttributeWhereInput(),
+ filter=AttributeFilterInput(
+ description=(
+ "Filtering options for attributes of this product type. "
+ f"{DEPRECATED_IN_3X_INPUT} Use `where` filter instead."
+ )
+ ),
+ where=AttributeWhereInput(
+ description="Where filtering options for attributes of this product type."
+ ),
+ search=graphene.String(description="Search attributes."),
description="List of attributes which can be assigned to this product type.",
permissions=[ProductPermissions.MANAGE_PRODUCTS],
)
@@ -1890,7 +1904,9 @@ class ProductType(ModelObjectType[models.ProductType]):
return _resolve_products(None)
@staticmethod
- def resolve_available_attributes(root: models.ProductType, info, **kwargs):
+ def resolve_available_attributes(
+ root: models.ProductType, info, search=None, **kwargs
+ ):
qs = attribute_models.Attribute.objects.using(
get_database_connection_name(info.context)
).get_unassigned_product_type_attributes(root.pk)
@@ -1898,6 +1914,8 @@ class ProductType(ModelObjectType[models.ProductType]):
qs = filter_connection_queryset(
qs, kwargs, info.context, allow_replica=info.context.allow_replica
)
+ if search:
+ qs = filter_attribute_search(qs, None, search)
return create_connection_slice(qs, info, kwargs, AttributeCountableConnection)
@staticmethod
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 8b06c9d6f5..3cec75b4da 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -341,7 +341,7 @@ type Query {
"""Filtering options for categories."""
filter: CategoryFilterInput
- """Where filtering options."""
+ """Where filtering options for categories."""
where: CategoryWhereInput
"""Sort categories."""
@@ -411,7 +411,7 @@ type Query {
"""Filtering options for collections."""
filter: CollectionFilterInput
- """Where filtering options."""
+ """Where filtering options for collections."""
where: CollectionWhereInput
"""Sort collections."""
@@ -466,9 +466,9 @@ type Query {
"""
products(
"""Filtering options for products."""
- filter: ProductFilterInput
+ filter: ProductFilterInput @deprecated(reason: "Use `where` filter instead.")
- """Where filtering options."""
+ """Where filtering options for products."""
where: ProductWhereInput
"""Sort products."""
@@ -558,7 +558,7 @@ type Query {
"""Filtering options for product variant."""
filter: ProductVariantFilterInput
- """Where filtering options."""
+ """Where filtering options for product variants."""
where: ProductVariantWhereInput
"""Sort products variants."""
@@ -795,7 +795,7 @@ type Query {
sortBy: OrderSortingInput
"""Filtering options for orders."""
- filter: OrderFilterInput
+ filter: OrderFilterInput @deprecated(reason: "Use `where` filter instead.")
"""
Where filtering options for orders.
@@ -1191,7 +1191,7 @@ type Query {
Requires one of the following permissions: MANAGE_DISCOUNTS.
"""
promotions(
- """Where filtering options."""
+ """Where filtering options for promotions."""
where: PromotionWhereInput
"""Sort promotions."""
@@ -1343,9 +1343,9 @@ type Query {
"""List of the shop's attributes."""
attributes(
"""Filtering options for attributes."""
- filter: AttributeFilterInput
+ filter: AttributeFilterInput @deprecated(reason: "Use `where` filter instead.")
- """Filtering options for attributes."""
+ """Where filtering options for attributes."""
where: AttributeWhereInput
"""Search attributes."""
@@ -5685,7 +5685,7 @@ type Product implements Node & ObjectWithMetadata @doc(category: "Products") {
"""Filtering options for product variant."""
filter: ProductVariantFilterInput
- """Where filtering options."""
+ """Where filtering options for product variants."""
where: ProductVariantWhereInput
"""Sort products variants."""
@@ -5863,9 +5863,15 @@ type ProductType implements Node & ObjectWithMetadata @doc(category: "Products")
Requires one of the following permissions: MANAGE_PRODUCTS.
"""
availableAttributes(
- filter: AttributeFilterInput
+ """Filtering options for attributes of this product type."""
+ filter: AttributeFilterInput @deprecated(reason: "Use `where` filter instead.")
+
+ """Where filtering options for attributes of this product type."""
where: AttributeWhereInput
+ """Search attributes."""
+ search: String
+
"""Return the elements in the list that come before the specified cursor."""
before: String
@@ -6632,15 +6638,20 @@ type Category implements Node & ObjectWithMetadata @doc(category: "Products") {
List of products in the category. Requires the following permissions to include the unpublished items: MANAGE_ORDERS, MANAGE_DISCOUNTS, MANAGE_PRODUCTS.
"""
products(
- """Filtering options for products."""
+ """
+ Filtering options for products. {DEPRECATED_IN_3X_INPUT} Use `where` filter instead.
+ """
filter: ProductFilterInput
- """Filtering options for products."""
+ """Where filtering options for products."""
where: ProductWhereInput
"""Sort products."""
sortBy: ProductOrder
+ """Search products."""
+ search: String
+
"""Slug of a channel for which the data should be returned."""
channel: String
@@ -7990,11 +8001,14 @@ type Collection implements Node & ObjectWithMetadata @doc(category: "Products")
"""List of products in this collection."""
products(
"""Filtering options for products."""
- filter: ProductFilterInput
+ filter: ProductFilterInput @deprecated(reason: "Use `where` filter instead.")
- """Filtering options for products."""
+ """Where filtering options for products."""
where: ProductWhereInput
+ """Search products."""
+ search: String
+
"""Sort products."""
sortBy: ProductOrder
@@ -8562,9 +8576,15 @@ type PageType implements Node & ObjectWithMetadata @doc(category: "Pages") {
Requires one of the following permissions: MANAGE_PAGES, MANAGE_PAGE_TYPES_AND_ATTRIBUTES.
"""
availableAttributes(
- filter: AttributeFilterInput
+ """Filtering options for attributes."""
+ filter: AttributeFilterInput @deprecated(reason: "Use `where` filter instead.")
+
+ """Where filtering options for attributes."""
where: AttributeWhereInput
+ """Search attributes."""
+ search: String
+
"""Return the elements in the list that come before the specified cursor."""
before: String