@@ -12,6 +12,8 @@ import { cursorPageInfoField, edgeNodes, todoItemFields } from './graphql-fragme
12
12
describe ( 'TodoItemResolver (cursor pagination - fetch all with negative enabled)' , ( ) => {
13
13
let app : INestApplication
14
14
15
+ const describeIf = ( condition : boolean ) => ( condition ? describe : describe . skip )
16
+
15
17
beforeAll ( async ( ) => {
16
18
const moduleRef = await Test . createTestingModule ( {
17
19
imports : [ AppModule ]
@@ -36,14 +38,14 @@ describe('TodoItemResolver (cursor pagination - fetch all with negative enabled)
36
38
37
39
describe ( 'query' , ( ) => {
38
40
describe ( 'paging' , ( ) => {
39
- it ( 'should return all the nodes after the given cursor ' , ( ) =>
41
+ it ( 'should return all the nodes' , ( ) =>
40
42
request ( app . getHttpServer ( ) )
41
43
. post ( '/graphql' )
42
44
. send ( {
43
45
operationName : null ,
44
46
variables : { } ,
45
47
query : `{
46
- todoItemCursorFetchWithNegativeEnables(paging: {first: -1, after: "YXJyYXljb25uZWN0aW9uOjE=" }) {
48
+ todoItemCursorFetchWithNegativeEnables(paging: {first: -1}) {
47
49
${ cursorPageInfoField }
48
50
${ edgeNodes ( todoItemFields ) }
49
51
}
@@ -56,41 +58,94 @@ describe('TodoItemResolver (cursor pagination - fetch all with negative enabled)
56
58
expect ( pageInfo ) . toEqual ( {
57
59
endCursor : 'YXJyYXljb25uZWN0aW9uOjk5' ,
58
60
hasNextPage : false ,
59
- hasPreviousPage : true ,
60
- startCursor : 'YXJyYXljb25uZWN0aW9uOjI ='
61
+ hasPreviousPage : false ,
62
+ startCursor : 'YXJyYXljb25uZWN0aW9uOjA ='
61
63
} )
62
- expect ( edges ) . toHaveLength ( 98 )
64
+ expect ( edges ) . toHaveLength ( 100 )
63
65
64
- expect ( edges . map ( ( e ) => e . node ) ) . toEqual ( todoItems . slice ( 2 ) )
66
+ expect ( edges . map ( ( e ) => e . node ) ) . toEqual ( todoItems )
65
67
} ) )
66
- it ( 'should return all the nodes before the given cursor' , ( ) =>
67
- request ( app . getHttpServer ( ) )
68
- . post ( '/graphql' )
69
- . send ( {
70
- operationName : null ,
71
- variables : { } ,
72
- query : `{
68
+
69
+ describeIf ( process . env . NESTJS_QUERY_DB_TYPE == 'postgres' ) ( 'postgres' , ( ) => {
70
+ it ( 'should return all the nodes after the given cursor' , ( ) =>
71
+ request ( app . getHttpServer ( ) )
72
+ . post ( '/graphql' )
73
+ . send ( {
74
+ operationName : null ,
75
+ variables : { } ,
76
+ query : `{
77
+ todoItemCursorFetchWithNegativeEnables(paging: {first: -1, after: "YXJyYXljb25uZWN0aW9uOjE="}) {
78
+ ${ cursorPageInfoField }
79
+ ${ edgeNodes ( todoItemFields ) }
80
+ }
81
+ }`
82
+ } )
83
+ . expect ( 200 )
84
+ . then ( ( { body } ) => {
85
+ const { edges, pageInfo } : CursorConnectionType < TodoItemCursorFetchWithNegativeEnableDTO > =
86
+ body . data . todoItemCursorFetchWithNegativeEnables
87
+ expect ( pageInfo ) . toEqual ( {
88
+ endCursor : 'YXJyYXljb25uZWN0aW9uOjk5' ,
89
+ hasNextPage : false ,
90
+ hasPreviousPage : true ,
91
+ startCursor : 'YXJyYXljb25uZWN0aW9uOjI='
92
+ } )
93
+ expect ( edges ) . toHaveLength ( 98 )
94
+
95
+ expect ( edges . map ( ( e ) => e . node ) ) . toEqual ( todoItems . slice ( 2 ) )
96
+ } ) )
97
+ } )
98
+
99
+ describeIf ( process . env . NESTJS_QUERY_DB_TYPE == 'mysql' ) ( 'mysql' , ( ) => {
100
+ it ( 'should return an error when requesting all the nodes after the given cursor' , ( ) =>
101
+ request ( app . getHttpServer ( ) )
102
+ . post ( '/graphql' )
103
+ . send ( {
104
+ operationName : null ,
105
+ variables : { } ,
106
+ query : `{
107
+ todoItemCursorFetchWithNegativeEnables(paging: {first: -1, after: "YXJyYXljb25uZWN0aW9uOjE="}) {
108
+ ${ cursorPageInfoField }
109
+ ${ edgeNodes ( todoItemFields ) }
110
+ }
111
+ }`
112
+ } )
113
+ . expect ( 200 )
114
+ . then ( ( { body } ) => {
115
+ expect ( body . errors ) . toBeDefined ( )
116
+ expect ( body . errors ) . toHaveLength ( 1 )
117
+ expect ( body . errors [ 0 ] . message ) . toContain ( 'RDBMS does not support OFFSET without LIMIT in SELECT statements' )
118
+ expect ( body . data ) . toBeNull ( )
119
+ } ) )
120
+ } )
121
+ } )
122
+ it ( 'should return an error when request all the nodes before the given cursor' , ( ) =>
123
+ request ( app . getHttpServer ( ) )
124
+ . post ( '/graphql' )
125
+ . send ( {
126
+ operationName : null ,
127
+ variables : { } ,
128
+ query : `{
73
129
todoItemCursorFetchWithNegativeEnables(paging: {last: -1, before: "YXJyYXljb25uZWN0aW9uOjk4"}) {
74
130
${ cursorPageInfoField }
75
131
${ edgeNodes ( todoItemFields ) }
76
132
}
77
133
}`
134
+ } )
135
+ . expect ( 200 )
136
+ . then ( ( { body } ) => {
137
+ const { edges, pageInfo } : CursorConnectionType < TodoItemCursorFetchWithNegativeEnableDTO > =
138
+ body . data . todoItemCursorFetchWithNegativeEnables
139
+ expect ( pageInfo ) . toEqual ( {
140
+ endCursor : 'YXJyYXljb25uZWN0aW9uOjk3' ,
141
+ hasNextPage : true ,
142
+ hasPreviousPage : false ,
143
+ startCursor : 'YXJyYXljb25uZWN0aW9uOjA='
78
144
} )
79
- . expect ( 200 )
80
- . then ( ( { body } ) => {
81
- const { edges, pageInfo } : CursorConnectionType < TodoItemCursorFetchWithNegativeEnableDTO > =
82
- body . data . todoItemCursorFetchWithNegativeEnables
83
- expect ( pageInfo ) . toEqual ( {
84
- endCursor : 'YXJyYXljb25uZWN0aW9uOjk3' ,
85
- hasNextPage : true ,
86
- hasPreviousPage : false ,
87
- startCursor : 'YXJyYXljb25uZWN0aW9uOjA='
88
- } )
89
- expect ( edges ) . toHaveLength ( 98 )
145
+ expect ( edges ) . toHaveLength ( 98 )
90
146
91
- expect ( edges . map ( ( e ) => e . node ) ) . toEqual ( todoItems . slice ( 0 , 98 ) )
92
- } ) )
93
- } )
147
+ expect ( edges . map ( ( e ) => e . node ) ) . toEqual ( todoItems . slice ( 0 , 98 ) )
148
+ } ) )
94
149
} )
95
150
96
151
afterAll ( async ( ) => {
0 commit comments