Skip to content

Relay pagination hasPreviousPage bug  #796

Closed
@sebastiandev

Description

@sebastiandev

Every time you make a query with a first and after parameters, hasPreviousPage is false.

In order to reproduce, make a query

query {
    some_query(first: 1) {
      edges {
        node {
          name
        }
        cursor
      }
   }
}

And then another one using the cursor

query {
    some_query(first: 1, after: "somecursor") {
      pageInfo {
        hasNextPage
        hasPreviousPage
        startCursor
        endCursor
      }
      edges {
        node {
          name
        }
        cursor
      }
    }
}

In here I'm not sure why it adds 1, but at the end when calculating hasPreviousPage this will cause lower_offset to be equal to start_offset and return False

start_offset = max(
        slice_start - 1,
        after_offset,
        -1
) + 1

In here to calculate hasPreviousPage it only uses last so when you are using first. will always be false

    first_edge_cursor = edges[0].cursor if edges else None
    last_edge_cursor = edges[-1].cursor if edges else None
    lower_bound = after_offset + 1 if after else 0
    upper_bound = before_offset if before else list_length

    return connection_type(
        edges=edges,
        page_info=pageinfo_type(
            start_cursor=first_edge_cursor,
            end_cursor=last_edge_cursor,
            has_previous_page=isinstance(last, int) and start_offset > lower_bound,
            has_next_page=isinstance(first, int) and end_offset < upper_bound
        )
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions