Graphcool / graphcool-framework

Apache License 2.0
1.77k stars 131 forks source link

Cursor pagination unreliable when sorting criterion field value is not unique #522

Open c10b10 opened 6 years ago

c10b10 commented 6 years ago

Imagine a Post model that is sorted by createdAt, that has the following data:

[
{ id: "ID4", creationDate: "2018-05-11T14:02:00.000Z"},
{ id: "ID3", creationDate: "2018-05-11T13:01:00.000Z"},
{ id: "ID2", creationDate: "2018-05-11T13:01:00.000Z"},
{ id: "ID1", creationDate: "2018-05-11T10:00:00.000Z"}
]

The ID2 and ID3 posts have the same createdAt field value. A query with arguments allPosts(orderBy: createdAt_DESC, first: 3) will return posts ID4, ID3, ID2.

Imagine this is part of a pagination sequence, so we would next call allPosts(orderBy: createdAt_DESC, first: 3, after: "ID2"). Due to the fact that posts ID2 and ID3 have the same field value for the ordering field, this query will return ID3, ID1 instead of the expected single ID1.