Skip to content

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

Change order object list to order object in GraphQL API

fowczarek582884db6183
diff --git a/saleor/graphql/product/filters.py b/saleor/graphql/product/filters.py
index c5e60cd811..4fb28940da 100644
--- a/saleor/graphql/product/filters.py
+++ b/saleor/graphql/product/filters.py
@@ -54,9 +54,7 @@ def filter_products_by_collections(qs, collections):
return qs.filter(collections__in=collections)
-def sort_qs(qs, sort_by):
- sort_order_list = []
- for sort_field in sort_by:
- sort_order_list.append(sort_field['direction'] + sort_field['field'])
- qs = qs.order_by(*sort_order_list)
+def sort_qs(qs, order_object):
+ if order_object:
+ qs = qs.order_by(order_object['direction'] + order_object['field'])
return qs
diff --git a/saleor/graphql/product/schema.py b/saleor/graphql/product/schema.py
index f634986fe4..fe780143af 100644
--- a/saleor/graphql/product/schema.py
+++ b/saleor/graphql/product/schema.py
@@ -61,7 +61,7 @@ class ProductQueries(graphene.ObjectType):
description='Filter by price less than or equal to the given value.'),
price_gte=graphene.Float(
description='Filter by price greater than or equal to the given value.'),
- sort_by=graphene.List(
+ sort_by=graphene.Argument(
ProductOrder, description='Sort products.'),
stock_availability=graphene.Argument(
StockAvailability,
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
index d4092bd786..b607f044df 100644
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -142,10 +142,10 @@ class SelectedAttribute(graphene.ObjectType):
class ProductOrder(graphene.InputObjectType):
field = graphene.Argument(
ProductOrderField, required=True,
- description='Allows selecting field to sort.')
+ description='Sort products by the selected field.')
direction = graphene.Argument(
OrderDirection, required=True,
- description='Determines how the field is being sorted.')
+ description='Specifies the direction in which to sort products')
class ProductVariant(CountableDjangoObjectType):