Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add order_by argument; rename filter to attributes
Marcin Gębala1959e3d49063
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.pyindex dd872f13f4..93f3e8c7b0 100644--- a/saleor/graphql/api.py+++ b/saleor/graphql/api.py@@ -7,7 +7,7 @@ from graphene_django.debug import DjangoDebugfrom ..product.models import (AttributeChoiceValue, Category, Product,ProductAttribute, ProductImage, ProductVariant)-from .scalars import FilterScalar+from .scalars import AttributesFilterScalarfrom .utils import DjangoPkInterface, get_object_or_none@@ -47,7 +47,9 @@ class ProductType(DjangoObjectType):class CategoryType(DjangoObjectType):products = relay.ConnectionField(- ProductType, filter=graphene.List(FilterScalar))+ ProductType,+ attributes=graphene.List(AttributesFilterScalar),+ order_by=graphene.String())class Meta:model = Category@@ -55,8 +57,8 @@ class CategoryType(DjangoObjectType):def resolve_products(self, args, context, info):qs = self.products.prefetch_for_api()- filter = args.get('filter')- if filter:+ attributes_filter = args.get('attributes')+ if attributes_filter:filter_obj = {}for attr_pk, attr_val_pk in filter:try:@@ -65,6 +67,10 @@ class CategoryType(DjangoObjectType):except ValueError:passqs = qs.filter(**filter_obj)++ order_by = args.get('order_by')+ if order_by:+ qs = qs.order_by(order_by)return qsdiff --git a/saleor/graphql/scalars.py b/saleor/graphql/scalars.pyindex ada488e10f..75562b5b38 100644--- a/saleor/graphql/scalars.py+++ b/saleor/graphql/scalars.py@@ -2,7 +2,7 @@ from graphene.types import Scalarfrom graphql.language import ast-class FilterScalar(Scalar):+class AttributesFilterScalar(Scalar):@staticmethoddef coerce_filter(value):