@@ -104,9 +104,10 @@ def fields(self):
104
104
def get_query (cls , model , info , ** args ):
105
105
106
106
if not callable (getattr (model , 'objects' , None )):
107
- return []
107
+ return [], 0
108
108
109
109
objs = model .objects ()
110
+
110
111
if args :
111
112
reference_fields = get_model_reference_fields (model )
112
113
reference_args = {}
@@ -138,14 +139,18 @@ def get_query(cls, model, info, **args):
138
139
if before is not None :
139
140
_before = int (from_global_id (before )[- 1 ])
140
141
objs = objs [:_before ]
142
+ # Not sure if this is in the correct place yet
143
+ list_length = objs .count ()
141
144
142
145
if first is not None :
143
146
objs = objs [:first ]
144
147
if last is not None :
145
148
# https://github.com/graphql-python/graphene-mongo/issues/20
146
149
objs = objs [- (last + 1 ):]
150
+ else :
151
+ list_length = objs .count ()
147
152
148
- return objs
153
+ return objs , list_length
149
154
150
155
# noqa
151
156
@classmethod
@@ -159,8 +164,9 @@ def merge_querysets(cls, default_queryset, queryset):
159
164
def connection_resolver (cls , resolver , connection , model , root , info , ** args ):
160
165
iterable = resolver (root , info , ** args )
161
166
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 )
164
170
connection = connection_from_list_slice (
165
171
iterable ,
166
172
args ,
0 commit comments