graphql / graphql/graphql-relay-js

[RFC] Backwards arguments are equivalent to forward arguments

Open
#204 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.5k
Forks
177
Avg merge
10m
Merged PRs (30d)
1

Description

I wrote a little about it [here](https://medium.com/@nijynot/foward-and-backward-pagination-arguments-are-equivalent-f1b4a01f3070), but basically `after = Math.max(before - last - 1, 0)`.

So if you implement `first` and `after`, you automatically get the functionality of `last` and `before` without needing to change much at all as `first` and `after` is the same as `last` and `before`.
It makes me think that the equivalency should be in the spec and that we should add the function below to `graphql-relay-js`.
```
export function transformBackwardToForward(args) {
const { last, before } = args;
const afterOffset = Math.max(cursorToOffset(before) - last - 1, 0);

return { first: last, after: offsetToCursor(afterOffset) };
}
```
Has anyone else solved pagination this way?
This might be worth looking into as it seems that many have problems with pagination by looking at #94.
What do you guys think about this implementation overall, good/bad?

Contributor guide

Open the contributing guide

Research direction

Start with the linked article and the proposed transformBackwardToForward(args) function in the issue. Review how graphql-relay-js currently handles forward and backward pagination, then determine whether the equivalence belongs in the specification and whether this helper should be added. Done means the project has a settled decision and an agreed implementation scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.