File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,11 @@ export const connectionFromArray = <T>(
59
59
) : Connection < T > => {
60
60
if ( totalCount ) {
61
61
const { after, before, first } = args // after and before should not appear together
62
- const offset = before ? - cursorToIndex ( before ) : after ? cursorToIndex ( after ) + 1 : 0
62
+ const offset = before
63
+ ? cursorToIndex ( before ) - ( first ?? 0 )
64
+ : after
65
+ ? cursorToIndex ( after ) + 1
66
+ : 0
63
67
64
68
const edges = data . map ( ( value , index ) => ( {
65
69
cursor : indexToCursor ( index + offset ) ,
@@ -79,8 +83,11 @@ export const connectionFromArray = <T>(
79
83
const beforeIndex = cursorToIndex ( before )
80
84
hasPreviousPage = beforeIndex >= ( first ? first : 0 )
81
85
} else {
82
- hasPreviousPage = first ? first - cursorToIndex ( firstEdge . cursor ) > 0 : cursorToIndex ( firstEdge . cursor ) > 0
86
+ hasPreviousPage = first
87
+ ? first - cursorToIndex ( firstEdge . cursor ) > 0
88
+ : cursorToIndex ( firstEdge . cursor ) > 0
83
89
}
90
+ console . log ( `first cursor is: ` , cursorToIndex ( firstEdge . cursor ) )
84
91
85
92
if ( lastEdge ) {
86
93
hasNextPage = cursorToIndex ( lastEdge . cursor ) + 1 < totalCount
You can’t perform that action at this time.
0 commit comments