Skip to content

Commit 95fb908

Browse files
author
Victor
committed
added tests for last n
1 parent 9b0ed7f commit 95fb908

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

graphene_mongo/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_query(cls, model, info, **args):
122122
objs = objs[:first]
123123
if last is not None:
124124
# fix for https://github.com/graphql-python/graphene-mongo/issues/20
125-
objs = objs[-last:]
125+
objs = objs[-(last+1):]
126126

127127
return objs
128128

graphene_mongo/tests/test_relay_query.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,48 @@ class Query(graphene.ObjectType):
447447
assert not result.errors
448448
assert json.dumps(result.data, sort_keys=True) == json.dumps(expected, sort_keys=True)
449449

450+
451+
def test_should_last_n():
452+
class Query(graphene.ObjectType):
453+
players = MongoengineConnectionField(PlayerNode)
454+
455+
query = '''
456+
query EditorQuery {
457+
players(last: 2) {
458+
edges {
459+
cursor,
460+
node {
461+
firstName
462+
}
463+
}
464+
}
465+
}
466+
'''
467+
expected = {
468+
'players': {
469+
'edges': [
470+
{
471+
'cursor': 'YXJyYXljb25uZWN0aW9uOjE=',
472+
'node': {
473+
'firstName': 'Magic',
474+
}
475+
},
476+
{
477+
'cursor': 'YXJyYXljb25uZWN0aW9uOjI=',
478+
'node': {
479+
'firstName': 'Larry',
480+
}
481+
}
482+
]
483+
}
484+
}
485+
schema = graphene.Schema(query=Query)
486+
result = schema.execute(query)
487+
488+
assert not result.errors
489+
assert json.dumps(result.data, sort_keys=True) == json.dumps(expected, sort_keys=True)
490+
491+
450492
def test_should_self_reference():
451493

452494
class Query(graphene.ObjectType):

0 commit comments

Comments
 (0)