Skip to content

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

Open
@nijynot

Description

@nijynot

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?

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