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

[RFC] Backwards arguments are equivalent to forward arguments #204

Open
nijynot opened this issue Feb 18, 2018 · 0 comments
Open

[RFC] Backwards arguments are equivalent to forward arguments #204

nijynot opened this issue Feb 18, 2018 · 0 comments

Comments

@nijynot
Copy link

nijynot commented Feb 18, 2018

I wrote a little about it here, 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?

@nijynot nijynot changed the title Backwards arguments are equivalent to forward arguments [RFC] Backwards arguments are equivalent to forward arguments Feb 18, 2018
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

1 participant