# Buggy code
def resolve_connection(cls, connection, args, iterable, max_limit=None):
    iterable = maybe_queryset(iterable)

    if isinstance(iterable, QuerySet):
        list_length = iterable.count()
        list_slice_length = (
            min(max_limit, list_length) if max_limit is not None else list_length
        )
    else:
        list_length = len(iterable)
        list_slice_length = (
            min(max_limit, list_length) if max_limit is not None else list_length
        )

    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,
        slice_start=after,
        list_length=list_length,
        list_slice_length=list_slice_length,
        connection_type=connection,
        edge_type=connection.Edge,
        pageinfo_type=PageInfo,
    )
    connection.iterable = iterable
    connection.length = list_length
    return connection


# Traceback (AssertionError)
Traceback (most recent call last):
File "/home/bellini/dev/cliqueimudei/cliqueimudei/backend/cm/urls.py", line 53, in execute_graphql_request
raise error.original_error
File "/home/bellini/.virtualenvs/cm/lib/python3.8/site-packages/promise/promise.py", line 489, in _resolve_from_executor
executor(resolve, reject)
File "/home/bellini/.virtualenvs/cm/lib/python3.8/site-packages/promise/promise.py", line 756, in executor
return resolve(f(*args, **kwargs))
File "/home/bellini/.virtualenvs/cm/lib/python3.8/site-packages/graphql/execution/middleware.py", line 75, in make_it_promise
return next(*args, **kwargs)
File "/home/bellini/.virtualenvs/cm/lib/python3.8/site-packages/graphene_django/fields.py", line 216, in connection_resolver
return on_resolve(iterable)
File "/home/bellini/.virtualenvs/cm/lib/python3.8/site-packages/graphene_django/fields.py", line 153, in resolve_connection
connection = connection_from_list_slice(
File "/home/bellini/.virtualenvs/cm/lib/python3.8/site-packages/graphql_relay/connection/arrayconnection.py", line 82, in connection_from_list_slice
_slice = list_slice[
File "/home/bellini/.virtualenvs/cm/lib/python3.8/site-packages/django/db/models/query.py", line 290, in __getitem__
assert ((not isinstance(k, slice) and (k >= 0)) or
AssertionError: Negative indexing is not supported.

# Fixed code
def resolve_connection(cls, connection, args, iterable, max_limit=None):
    iterable = maybe_queryset(iterable)

    if isinstance(iterable, QuerySet):
        list_length = iterable.count()
        list_slice_length = (
            min(max_limit, list_length) if max_limit is not None else list_length
        )
    else:
        list_length = len(iterable)
        list_slice_length = (
            min(max_limit, list_length) if max_limit is not None else list_length
        )

    # If after is higher than list_length, connection_from_list_slice
    # would try to do a negative slicing which makes django throw an
    # AssertionError
    after = min(get_offset_with_default(args.get("after"), -1) + 1, list_length)

    if max_limit is not None and "first" not in args:
        args["first"] = max_limit

    connection = connection_from_list_slice(
        iterable[after:],
        args,
        slice_start=after,
        list_length=list_length,
        list_slice_length=list_slice_length,
        connection_type=connection,
        edge_type=connection.Edge,
        pageinfo_type=PageInfo,
    )
    connection.iterable = iterable
    connection.length = list_length
    return connection