Skip to content

Commit

Permalink
Merge pull request #39 from FloatingGhost/master
Browse files Browse the repository at this point in the history
Fix: Don't use negative integers to slice
  • Loading branch information
abawchen committed Jul 16, 2018
2 parents da390d0 + 5d7a1fb commit 1e1c59b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions graphene_mongo/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from graphql_relay.node.node import from_global_id
from graphene.types.argument import to_arguments


from .utils import get_model_reference_fields


Expand Down Expand Up @@ -142,7 +141,7 @@ def get_query(cls, model, info, **args):
objs = objs[:first]
if last is not None:
# https://github.com/graphql-python/graphene-mongo/issues/20
objs = objs[-(last+1):]
objs = objs[max(0, list_length - last):]
else:
list_length = objs.count()

Expand All @@ -159,10 +158,16 @@ def merge_querysets(cls, default_queryset, queryset):
@classmethod
def connection_resolver(cls, resolver, connection, model, root, info, **args):
iterable = resolver(root, info, **args)

if not iterable:
iterable, _len = cls.get_query(model, info, **args)

if root:
# If we have a root, we must be at least 1 layer in, right?
_len = 0
else:
_len = len(iterable)

connection = connection_from_list_slice(
iterable,
args,
Expand Down

0 comments on commit 1e1c59b

Please sign in to comment.