diff --git a/graphene-django/graphene_django/fields.py b/graphene-django/graphene_django/fields.py index 4488f178..b23a4b65 100644 --- a/graphene-django/graphene_django/fields.py +++ b/graphene-django/graphene_django/fields.py @@ -1,7 +1,7 @@ from functools import partial from django.db.models.query import QuerySet -from graphene.relay import ConnectionField +from graphene.relay import ConnectionField, PageInfo from graphql_relay.connection.arrayconnection import connection_from_list_slice from .utils import maybe_queryset, DJANGO_FILTER_INSTALLED @@ -40,6 +40,7 @@ class DjangoConnectionField(ConnectionField): list_slice_length=_len, connection_type=connection, edge_type=connection.Edge, + pageinfo_type=PageInfo, ) connection.iterable = iterable connection.length = _len diff --git a/graphene-django/graphene_django/tests/test_query.py b/graphene-django/graphene_django/tests/test_query.py index 7cb2055c..80a45e91 100644 --- a/graphene-django/graphene_django/tests/test_query.py +++ b/graphene-django/graphene_django/tests/test_query.py @@ -9,6 +9,7 @@ from graphene.relay import Node from ..compat import MissingType, RangeField from ..types import DjangoObjectType +from ..fields import DjangoConnectionField from ..registry import reset_global_registry, get_global_registry from .models import Article, Reporter @@ -204,3 +205,48 @@ def test_should_node(): result = schema.execute(query) assert not result.errors assert result.data == expected + + +def test_should_query_connectionfields(): + class ReporterType(DjangoObjectType): + + class Meta: + model = Reporter + interfaces = (Node, ) + only_fields = ('articles', ) + + class Query(graphene.ObjectType): + all_reporters = DjangoConnectionField(ReporterType) + + def resolve_all_reporters(self, args, context, info): + return [Reporter(id=1)] + + schema = graphene.Schema(query=Query) + query = ''' + query ReporterConnectionQuery { + allReporters { + pageInfo { + hasNextPage + } + edges { + node { + id + } + } + } + } + ''' + result = schema.execute(query) + assert not result.errors + assert result.data == { + 'allReporters': { + 'pageInfo': { + 'hasNextPage': False, + }, + 'edges': [{ + 'node': { + 'id': 'UmVwb3J0ZXJUeXBlOjE=' + } + }] + } + }