Set first amount to max limit if not set (#993)

This commit is contained in:
Jonathan Kim 2020-06-25 15:10:56 +01:00 committed by GitHub
parent 3c229b619e
commit 3026181b28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -146,6 +146,9 @@ class DjangoConnectionField(ConnectionField):
after = get_offset_with_default(args.get("after"), -1) + 1
if max_limit is not None and "first" not in args:
args["first"] = max_limit
connection = connection_from_list_slice(
iterable[after:],
args,

View File

@ -1127,7 +1127,7 @@ def test_should_return_max_limit(graphene_settings):
def test_should_have_next_page(graphene_settings):
graphene_settings.RELAY_CONNECTION_MAX_LIMIT = 6
graphene_settings.RELAY_CONNECTION_MAX_LIMIT = 4
reporters = [Reporter(**kwargs) for kwargs in REPORTERS]
Reporter.objects.bulk_create(reporters)
db_reporters = Reporter.objects.all()
@ -1141,9 +1141,6 @@ def test_should_have_next_page(graphene_settings):
all_reporters = DjangoConnectionField(ReporterType)
schema = graphene.Schema(query=Query)
# Need first: 4 here to trigger the `has_next_page` logic in graphql-relay
# See `arrayconnection.py::connection_from_list_slice`:
# has_next_page=isinstance(first, int) and end_offset < upper_bound
query = """
query AllReporters($first: Int, $after: String) {
allReporters(first: $first, after: $after) {
@ -1160,7 +1157,7 @@ def test_should_have_next_page(graphene_settings):
}
"""
result = schema.execute(query, variable_values=dict(first=4))
result = schema.execute(query, variable_values={})
assert not result.errors
assert len(result.data["allReporters"]["edges"]) == 4
assert result.data["allReporters"]["pageInfo"]["hasNextPage"]