Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix page pagination
Adam Janik877dde27691d
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.pyindex 1700450809..c21b1ad887 100644--- a/saleor/graphql/api.py+++ b/saleor/graphql/api.py@@ -71,7 +71,7 @@ class Query(graphene.ObjectType):return page_models.Page.objects.get(slug=slug)return get_node(info, id, only_type=Page)- def resolve_pages(self, info):+ def resolve_pages(self, info, **kwargs):return resolve_pages(user=info.context.user)def resolve_product(self, info, id):diff --git a/saleor/graphql/page/types.py b/saleor/graphql/page/types.pyindex 361f24c6c5..cd8151d490 100644--- a/saleor/graphql/page/types.py+++ b/saleor/graphql/page/types.py@@ -9,5 +9,5 @@ class Page(CountableDjangoObjectType):description = """A static page that can be manually added by a shopoperator through the dashboard."""interfaces = [relay.Node]- model = models.Pagefilter_fields = ['id', 'name']+ model = models.Pagediff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.pyindex 3e74881bbd..56b00a9ba6 100644--- a/saleor/graphql/product/types.py+++ b/saleor/graphql/product/types.py@@ -79,7 +79,6 @@ class Product(CountableDjangoObjectType):size=graphene.Argument(graphene.String,description='Size of a thumbnail, for example 255x255.'))- # TODO: drop this field in favor of particular ones?availability = graphene.Field(ProductAvailability,description="""Informs about product's availability in the storefront,@@ -93,8 +92,6 @@ class Product(CountableDjangoObjectType):description='List of product attributes assigned to this product.')purchase_cost = graphene.Field(TaxedMoneyRange)gross_margin = graphene.List(GrossMargin)- price_range = graphene.Field(TaxedMoneyRange)- price_range_undiscounted = graphene.Field(TaxedMoneyRange)class Meta:description = """Represents an individual item for sale in the@@ -129,13 +126,6 @@ class Product(CountableDjangoObjectType):_, gross_margin = get_product_costs_data(self)return [GrossMargin(gross_margin[0], gross_margin[1])]- def resolve_price_range(self, info):- context = info.context- return self.get_price_range(discounts=context.discounts)-- def resolve_price_range_undiscounted(self, info):- return self.get_price_range()-class ProductType(CountableDjangoObjectType):products = DjangoFilterConnectionField(diff --git a/tests/test_graphql.py b/tests/test_graphql.pyindex 4231aceff9..60769c2242 100644--- a/tests/test_graphql.py+++ b/tests/test_graphql.py@@ -3,12 +3,14 @@ from unittest.mock import patchimport grapheneimport pytest+from django.forms.models import model_to_dictfrom django.shortcuts import reversefrom django.utils.text import slugifyfrom prices import Moneyfrom saleor.graphql.core.mutations import (ModelFormMutation, ModelFormUpdateMutation)+from saleor.page.models import Pagefrom saleor.product.models import (Category, Product, ProductAttribute, ProductType)@@ -528,7 +530,6 @@ def test_real_query(admin_client, product):content = get_graphql_content(response)assert 'errors' not in content-def test_page_query(client, page):page.is_visible = Truequery = """@@ -550,6 +551,40 @@ def test_page_query(client, page):assert page_data['slug'] == page.slug+def test_paginate_pages(client, page):+ page.is_visible = True+ data_02 = {+ 'slug': 'test02-url',+ 'title': 'Test page',+ 'content': 'test content',+ 'is_visible': True}+ data_03 = {+ 'slug': 'test03-url',+ 'title': 'Test page',+ 'content': 'test content',+ 'is_visible': True}++ page2 = Page.objects.create(**data_02)+ page3 = Page.objects.create(**data_03)+ query = """+ query PagesQuery {+ pages(first: 2) {+ edges {+ node {+ id+ title+ }+ }+ }+ }+ """+ response = client.post(+ reverse('api'), {'query': query})+ content = get_graphql_content(response)+ assert 'errors' not in content+ pages_data = content['data']['pages']+ assert len(pages_data['edges']) == 2+@patch('saleor.graphql.core.mutations.convert_form_fields')@patch('saleor.graphql.core.mutations.convert_form_field')def test_model_form_mutation(