graphql-sequelize: Pagination first/last/before/after can't go both ways

Originally I was having issues with last, but decided to try first because it’s simpler to understand and found that both are broken. I haven’t noticed this before now because I’ve just been doing infinite scrolling to append rows which means you only go one way either forwards/backwards.

Now I’ve got to create an actual previous/next pagination and discovered:

Consider these 10 rows: a, b, c, d, e, f, g, h, i, j

First

✓ first 2 (forward)

expected: a, b actual: a, b expected limit: ASC LIMIT 2 actual limit: ASC LIMIT 2

✓ first 2 after b (forward)

expected: c, d actual: c, d expected limit: ASC LIMIT 2, 2 actual limit: ASC LIMIT 2, 2

✗first 2 before c (back)

expected: a, b actual: d, e expected limit: ASC LIMIT 2 actual limit: ASC LIMIT 3, 2

Last

✓ last 2 (forward)

expected: j, i actual: j, i expected limit: DESC LIMIT 2 actual limit: DESC LIMIT 2

✓ last 2 before i (forward)

expected: h, g actual: h, g expected limit: DESC LIMIT 2, 2 actual limit: DESC LIMIT 2, 2

✗last 2 after h (back)

expected: j, i actual: f, e expected limit: DESC LIMIT 0, 2 actual limit: DESC LIMIT 3, 2

Investigated somewhat and so far I found that the cursors are these: base64(PREFIX + id + SEPERATOR + index)

So in the first set, the cursors look like:

  • arrayconnection$1$0
  • arrayconnection$2$1
  • arrayconnection$3$2
  • arrayconnection$4$3

Code for the limits and offsets generated are: https://github.com/mickhansen/graphql-sequelize/blob/d39d0ce48ea248831480161f1aeff68f240f7b5c/src/relay.js#L217-L219 https://github.com/mickhansen/graphql-sequelize/blob/d39d0ce48ea248831480161f1aeff68f240f7b5c/src/relay.js#L265-L270

Maybe that should be (need to test):

options.offset = args.after ? startIndex + 1 : options.offset - args.limit;

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 23 (21 by maintainers)

Most upvoted comments

as far as i can tell first: 2, before: "cursor" should behave the same way as first: 2