File tree 2 files changed +9
-4
lines changed
__tests__/types/connection 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -169,7 +169,7 @@ describe('ConnectionType', (): void => {
169
169
paging : createPage ( { last : 2 , before : 'YXJyYXljb25uZWN0aW9uOjM=' } ) ,
170
170
} ) ;
171
171
expect ( queryMany ) . toHaveBeenCalledTimes ( 1 ) ;
172
- expect ( queryMany ) . toHaveBeenCalledWith ( { paging : { limit : 2 , offset : 0 } } ) ;
172
+ expect ( queryMany ) . toHaveBeenCalledWith ( { paging : { limit : 3 , offset : 0 } } ) ;
173
173
expect ( response ) . toEqual ( {
174
174
edges : [
175
175
{
Original file line number Diff line number Diff line change @@ -35,10 +35,15 @@ export class CursorPager<DTO> {
35
35
}
36
36
37
37
async runQuery ( queryMany : QueryMany < DTO > , query : Query < DTO > , pagingMeta : PagingMeta ) : Promise < QueryResults < DTO > > {
38
- // if paging forward add 1 to limit for check for an additional page.
39
- const limit = pagingMeta . isForward ? pagingMeta . limit + 1 : pagingMeta . limit ;
38
+ // Add 1 to the limit so we will fetch an additional node
39
+ let limit = pagingMeta . limit + 1 ;
40
40
// if paging backwards remove one from the offset to check for a previous page.
41
- const offset = Math . max ( 0 , pagingMeta . isBackward ? pagingMeta . offset - 1 : pagingMeta . offset ) ;
41
+ let offset = pagingMeta . isBackward ? pagingMeta . offset - 1 : pagingMeta . offset ;
42
+ if ( offset < 0 ) {
43
+ // if the offset is < 0 it means we underflowed and that we cant have an extra page.
44
+ offset = 0 ;
45
+ limit = pagingMeta . limit ;
46
+ }
42
47
const nodes = await queryMany ( { ...query , paging : { limit, offset } } ) ;
43
48
// check if we have an additional node
44
49
// if paging forward that indicates we have a next page
You can’t perform that action at this time.
0 commit comments