Skip to content

Commit 7f8913f

Browse files
fix: Fix isValidPaging
1 parent a954f81 commit 7f8913f

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

examples/fetch-all-with-negative/e2e/todo-cursor-fetch-all-disable.resolver.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { TodoItemCursorFetchWithNegativeDisableDTO } from '../src/todo-item/dto/
99
import { refresh } from './fixtures'
1010
import { cursorPageInfoField, edgeNodes, todoItemFields } from './graphql-fragments'
1111

12-
describe('TodoItemResolver (cursor paginatino - fetch all with negative disabled)', () => {
12+
describe('TodoItemResolver (cursor pagination - fetch all with negative disabled)', () => {
1313
let app: INestApplication
1414

1515
beforeAll(async () => {

examples/fetch-all-with-negative/e2e/todo-cursor-fetch-all-enable.resolver.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { TodoItemCursorFetchWithNegativeEnableDTO } from '../src/todo-item/dto/t
99
import { refresh, todoItems } from './fixtures'
1010
import { cursorPageInfoField, edgeNodes, todoItemFields } from './graphql-fragments'
1111

12-
describe('TodoItemResolver (cursor paginatino - fetch all with negative enabled)', () => {
12+
describe('TodoItemResolver (cursor pagination - fetch all with negative enabled)', () => {
1313
let app: INestApplication
1414

1515
beforeAll(async () => {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE
2+
USER fetch_all_with_negative;
3+
CREATE
4+
DATABASE fetch_all_with_negative;
5+
GRANT ALL PRIVILEGES ON fetch_all_with_negative.* TO fetch_all_with_negative;

packages/query-graphql/src/types/connection/cursor/pager/pager.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ export class CursorPager<DTO> implements Pager<DTO, CursorPagerResult<DTO>> {
3737

3838
private isValidPaging(pagingMeta: PagingMeta<DTO, CursorPagingOpts<DTO>>): boolean {
3939
const minimumLimit = this.enableFetchAllWithNegative ? -1 : 1
40+
const hasLimit = 'limit' in pagingMeta.opts && pagingMeta.opts.limit !== null
4041
const isValidLimit = pagingMeta.opts.limit >= minimumLimit
42+
if (hasLimit && !isValidLimit) {
43+
return false
44+
}
45+
4146
if ('offset' in pagingMeta.opts) {
42-
return pagingMeta.opts.offset > 0 && isValidLimit
47+
return pagingMeta.opts.offset > 0 || hasLimit
4348
}
44-
return isValidLimit
49+
return hasLimit
4550
}
4651

4752
private async runQuery<Q extends Query<DTO>>(

0 commit comments

Comments
 (0)