diff options
author | Marcin Gębala <maarcin.gebala@gmail.com> | 2016-12-07 16:06:45 +0100 |
---|---|---|
committer | Marcin Gębala <maarcin.gebala@gmail.com> | 2017-01-04 11:19:51 +0100 |
commit | f23883f4e0120e86b2f3fd8a3a9b037ac65a026d (patch) | |
tree | 57e6021e9321bff89beda56b2cc94cb5888fb04e /saleor/graphql | |
parent | 8e27b2957de695228a0a9c4646d6e93dfe7379d1 (diff) | |
download | saleor-frontend-f23883f4e0120e86b2f3fd8a3a9b037ac65a026d.tar.gz saleor-frontend-f23883f4e0120e86b2f3fd8a3a9b037ac65a026d.tar.bz2 saleor-frontend-f23883f4e0120e86b2f3fd8a3a9b037ac65a026d.zip |
Refactor filter components; use normal list for returning categories from API
Diffstat (limited to 'saleor/graphql')
-rw-r--r-- | saleor/graphql/api.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.py index 6a628de5..249bdaac 100644 --- a/saleor/graphql/api.py +++ b/saleor/graphql/api.py @@ -51,7 +51,7 @@ ProductType.Connection = connection_with_count(ProductType) class CategoryType(DjangoObjectType): - url = graphene.String() + children = graphene.List(lambda: CategoryType) products = relay.ConnectionField( ProductType, attributes=graphene.Argument( @@ -68,14 +68,15 @@ class CategoryType(DjangoObjectType): price_gte=graphene.Argument( graphene.Float, description="""Get the products with price greater than or equal to the given value""")) + products_count = graphene.Int() + url = graphene.String() class Meta: model = Category interfaces = (relay.Node, DjangoPkInterface) - @graphene.resolve_only_args - def resolve_url(self): - return self.get_absolute_url() + def resolve_children(self, args, context, info): + return self.children.all() def resolve_products(self, args, context, info): qs = self.products.prefetch_for_api() @@ -114,6 +115,13 @@ class CategoryType(DjangoObjectType): qs = qs.filter(price__gte=price_gte) return qs.distinct() + def resolve_products_count(self, args, context, info): + return self.products.count() + + @graphene.resolve_only_args + def resolve_url(self): + return self.get_absolute_url() + class ProductVariantType(DjangoObjectType): stock_quantity = graphene.Int() @@ -172,7 +180,7 @@ class Viewer(graphene.ObjectType): product = graphene.Field( ProductType, pk=graphene.Argument(graphene.Int, required=True)) attributes = graphene.List(ProductAttributeType) - categories = relay.ConnectionField(CategoryType) + categories = graphene.List(CategoryType) def resolve_category(self, args, context, info): return get_object_or_none(Category, pk=args.get('pk')) |