Skip to content

Commit 98d6eda

Browse files
authored
Merge pull request #29 from noodlespace/master
Fix: Update hasNextPage, was always false before
2 parents f7229dc + 7d1b4ed commit 98d6eda

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

graphene_mongo/fields.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ def fields(self):
104104
def get_query(cls, model, info, **args):
105105

106106
if not callable(getattr(model, 'objects', None)):
107-
return []
107+
return [], 0
108108

109109
objs = model.objects()
110+
110111
if args:
111112
reference_fields = get_model_reference_fields(model)
112113
reference_args = {}
@@ -138,14 +139,18 @@ def get_query(cls, model, info, **args):
138139
if before is not None:
139140
_before = int(from_global_id(before)[-1])
140141
objs = objs[:_before]
142+
# Not sure if this is in the correct place yet
143+
list_length = objs.count()
141144

142145
if first is not None:
143146
objs = objs[:first]
144147
if last is not None:
145148
# https://github.com/graphql-python/graphene-mongo/issues/20
146149
objs = objs[-(last+1):]
150+
else:
151+
list_length = objs.count()
147152

148-
return objs
153+
return objs, list_length
149154

150155
# noqa
151156
@classmethod
@@ -159,8 +164,9 @@ def merge_querysets(cls, default_queryset, queryset):
159164
def connection_resolver(cls, resolver, connection, model, root, info, **args):
160165
iterable = resolver(root, info, **args)
161166
if not iterable:
162-
iterable = cls.get_query(model, info, **args)
163-
_len = len(iterable)
167+
iterable, _len = cls.get_query(model, info, **args)
168+
else:
169+
_len = len(iterable)
164170
connection = connection_from_list_slice(
165171
iterable,
166172
args,

graphene_mongo/tests/test_relay_query.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ class Query(graphene.ObjectType):
413413
firstName
414414
}
415415
}
416+
pageInfo {
417+
hasNextPage
418+
hasPreviousPage
419+
startCursor
420+
endCursor
421+
}
416422
}
417423
}
418424
'''
@@ -431,7 +437,13 @@ class Query(graphene.ObjectType):
431437
'firstName': 'Grant'
432438
}
433439
}
434-
]
440+
],
441+
'pageInfo': {
442+
'hasNextPage': True,
443+
'hasPreviousPage': False,
444+
'startCursor': 'xxx',
445+
'endCursor': 'xxx'
446+
}
435447
}
436448
}
437449
schema = graphene.Schema(query=Query)

0 commit comments

Comments
 (0)