diff --git a/graphene_django/fields.py b/graphene_django/fields.py index 980b9e8..ac7ce45 100644 --- a/graphene_django/fields.py +++ b/graphene_django/fields.py @@ -133,21 +133,23 @@ class DjangoConnectionField(ConnectionField): def resolve_connection(cls, connection, args, iterable, max_limit=None): iterable = maybe_queryset(iterable) - max_limit = max_limit or 0 if isinstance(iterable, QuerySet): list_length = iterable.count() - list_slice_length = max(max_limit, list_length) + list_slice_length = ( + min(max_limit, list_length) if max_limit is not None else list_length + ) else: list_length = len(iterable) - list_slice_length = max(max_limit, list_length) + list_slice_length = ( + min(max_limit, list_length) if max_limit is not None else list_length + ) after = get_offset_with_default(args.get("after"), -1) + 1 - list_slice_length += after connection = connection_from_list_slice( - iterable, + iterable[after:], args, - slice_start=0, + slice_start=after, list_length=list_length, list_slice_length=list_slice_length, connection_type=connection, diff --git a/graphene_django/tests/test_query.py b/graphene_django/tests/test_query.py index 3440586..64f54bb 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -1127,7 +1127,7 @@ def test_should_return_max_limit(graphene_settings): def test_should_have_next_page(graphene_settings): - graphene_settings.RELAY_CONNECTION_MAX_LIMIT = 4 + graphene_settings.RELAY_CONNECTION_MAX_LIMIT = 6 reporters = [Reporter(**kwargs) for kwargs in REPORTERS] Reporter.objects.bulk_create(reporters) db_reporters = Reporter.objects.all()