Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relay pagination hasPreviousPage bug #796

Closed
sebastiandev opened this issue Jul 10, 2018 · 2 comments
Closed

Relay pagination hasPreviousPage bug #796

sebastiandev opened this issue Jul 10, 2018 · 2 comments

Comments

@sebastiandev
Copy link

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
        )
)
@sebastiandev sebastiandev changed the title Relay pagination hasPreviousPage bug Relay pagination hasPreviousPage bug Jul 10, 2018
@sebastiandev
Copy link
Author

Found the issue in the grpahql-relay repo. Closing this

@joealcorn
Copy link

For anybody that comes across this ticket, the issue mentioned above graphql-python/graphql-relay-py#12, and there's a PR open with a fix too: graphql-python/graphql-relay-py#14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants