﻿# Relay backward pagination preserves the connection’s edge order

Relay last/before selects an earlier window without reversing edge order; edge cursors and directional PageInfo signals must be interpreted according to the traversal direction.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-relay-backward-edge-order/
Language: en

## Select an earlier window without reversing it

A research interface shows a connection of source revisions and lets the reader move backward through older pages. The [Cursor Connections specification](https://relay.dev/graphql/connections.htm) requires the same edge ordering for forward and backward pagination when other arguments are equal. `last` and `before` select a preceding window; they do not instruct the server to reverse that window's edges. A client that reverses again can display an inconsistent sequence when joining pages.

## Use the boundary belonging to the direction

The [GitHub GraphQL guide](https://docs.github.com/en/graphql/guides/using-pagination-in-the-graphql-api) demonstrates forward traversal with `endCursor` and `after`, and backward traversal with `startCursor` and `before`. Keep the query's connection and selection arguments aligned. An edge cursor describes a position in that connection; it should not be replaced by a node identifier or reused under different ordering assumptions merely because the same node appears in another list.

## Keep cursors opaque at the client boundary

The [GraphQL pagination guide](https://graphql.org/learn/pagination/) explains that a cursor is a property of the edge in the connection. Encoding that looks decodable does not authorize client reconstruction of another position. Store the returned string and use it under the same connection contract. The client needs the position token's role, not an inferred internal database key or offset that the server can change without redesigning the connection interface.

## Read PageInfo in the active direction

The specification gives stronger requirements for `hasNextPage` while moving forward and `hasPreviousPage` while moving backward. The opposite-direction flag may report false when determining that information efficiently is not possible. Do not infer that a forward page with a false previous-page flag necessarily starts at the collection's beginning. Use the guarantee associated with the chosen traversal when deciding whether to continue or disable a navigation control.

## Join pages using the declared edge sequence

Preserve returned edge order when appending a later window or placing an earlier window before the current one. [Task contracts](/journal/learn-codex-task-contract/) define the intended revision view; [tool observations](/journal/learn-codex-tool-observation/) retain query direction, boundary and PageInfo. This makes backward navigation a precise connection operation without turning opaque cursors into object identities, reversing the server's agreed order or presenting optional opposite-direction information as a complete inventory guarantee.
