olavim / objection-cursor

Cursor based pagination plugin for Objection.js
MIT License
30 stars 8 forks source link

hasPreviouse returning true on first query #13

Closed oscaroox closed 4 years ago

oscaroox commented 4 years ago

When my data amount exceeds the default limit of 50, hasPreviouse returns true.

It seems that the third query that fetches additional page info uses the default limit 50 instead of my own set limit.

query for results using my limit of 10

query-results

third query using limit of 50 to calculate remaining, hasNext .... query-info

steps to reproduce

plugins settings

 cursorMixin({
      limit: 50,
      pageInfo: {
          total: true,
          hasNext: true,
          hasPrevious: true,
      },
 }),

Insert more than the limit

const users = [...Array(60)].map(() =>
  UserModel.query().insert({
     firstName: faker.name.firstName(),
     balance: faker.random.number({ min: 1200, max: 4500 }),
  }),
);
await Promise.all(users);

get the first 10 items

const users = await UserModel.query()
    .orderBy('id')
    .limit(10)
    .cursorPage();

expect(users.pageInfo.hasNext).toBeTruthy(); // returns true
expect(users.pageInfo.hasPrevious).toBeFalsy(); // also returns true
olavim commented 4 years ago

Thanks for the issue. This should be fixed in version 1.0.1