Skip to content

Commit de59d26

Browse files
author
=
committed
Test: erro if last is greater than max - plus fix wrong variable
1 parent 65e6302 commit de59d26

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

graphene_django/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def connection_resolver(cls, resolver, connection, default_manager, max_limit,
116116
if last:
117117
assert last <= max_limit, (
118118
'Requesting {} records on the `{}` connection exceeds the `last` limit of {} records.'
119-
).format(first, info.field_name, max_limit)
119+
).format(last, info.field_name, max_limit)
120120
args['last'] = min(last, max_limit)
121121

122122
iterable = resolver(root, info, **args)

graphene_django/tests/test_query.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,53 @@ class Query(graphene.ObjectType):
606606
graphene_settings.RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST = False
607607

608608

609+
def test_should_error_if_last_is_greater_than_max():
610+
graphene_settings.RELAY_CONNECTION_MAX_LIMIT = 100
611+
612+
class ReporterType(DjangoObjectType):
613+
614+
class Meta:
615+
model = Reporter
616+
interfaces = (Node, )
617+
618+
class Query(graphene.ObjectType):
619+
all_reporters = DjangoConnectionField(ReporterType)
620+
621+
r = Reporter.objects.create(
622+
first_name='John',
623+
last_name='Doe',
624+
email='johndoe@example.com',
625+
a_choice=1
626+
)
627+
628+
schema = graphene.Schema(query=Query)
629+
query = '''
630+
query NodeFilteringQuery {
631+
allReporters(last: 101) {
632+
edges {
633+
node {
634+
id
635+
}
636+
}
637+
}
638+
}
639+
'''
640+
641+
expected = {
642+
'allReporters': None
643+
}
644+
645+
result = schema.execute(query)
646+
assert len(result.errors) == 1
647+
assert str(result.errors[0]) == (
648+
'Requesting 101 records on the `allReporters` connection '
649+
'exceeds the `last` limit of 100 records.'
650+
)
651+
assert result.data == expected
652+
653+
graphene_settings.RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST = False
654+
655+
609656
def test_should_query_promise_connectionfields():
610657
from promise import Promise
611658

0 commit comments

Comments
 (0)