Skip to content

connectionFromArray incorrectly calculates hasPreviousPage when paginating with first/afterΒ #286

@smoak

Description

@smoak

Summary

Using forward pagination (first/after) with connectionFromArray results in incorrect pageInfo.

Description

From the relay spec hasPreviousPage states:

If the client is paginating with first/after, then the client may return true if edges prior to after exist, if it can do so efficiently, otherwise may return false

However, hasPreviousPage is always false when using first/after:

return {
    edges,
    pageInfo: {
      startCursor: firstEdge ? firstEdge.cursor : null,
      endCursor: lastEdge ? lastEdge.cursor : null,
      hasPreviousPage:
        typeof last === 'number' ? startOffset > lowerBound : false,
      hasNextPage: typeof first === 'number' ? endOffset < upperBound : false,
    },
  };

The tests also seem to be incorrect as well.

Expectation

hasPreviousPage should be true when forward pagination arguments are used. There is enough information to calculate if edges prior to after exist.

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