Skip to content

[Relay] Pagination bug about previous/next #656

Closed
@Xuhao

Description

@Xuhao

According to this reply, there is a bug in Relay Cursor Connections Specification

hasPreviousPage will be false if the client is not paginating with last
hasNextPage will be false if the client is not paginating with first

And the implementation here:

def has_next_page
!!(first && paged_nodes && @has_next_page)
end
def has_previous_page
!!(last && starting_offset > 0)
end

So:
pageInfo.hasPreviousPage is always false when paging forwards, pageInfo.hasNextPage is always false when paging backwards


My env:
server side: graphql (1.5.5)
client side: react-relay@^0.10.0

My query to support pagination:

articles(first: $first, after: $afterCursor, last: $last, before: $beforeCursor)

when clicking next:

  goToNextPage = () => {
    this.props.relay.setVariables({
      first: pageSize,
      afterCursor: this.props.viewer.articles.pageInfo.endCursor,
      last: null,
      beforeCursor: null
    });
  };

when clicking previous:

  goToPrevPage = () => {
    this.props.relay.setVariables({
      last: pageSize,
      beforeCursor: this.props.viewer.articles.pageInfo.startCursor,
      first: null,
      afterCursor: null
    });
  };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions