@@ -106,10 +106,13 @@ describe('Functional', function () {
106106 class QueryType {
107107 @D . Field ( { pagination : true , type : graphql . GraphQLString } )
108108 async paginated (
109+ @D . Arg ( { name : 'offset' , type : graphql . GraphQLInt } ) offset : number ,
110+ @D . Arg ( { name : 'limit' , type : graphql . GraphQLInt } ) limit : number ,
109111 @D . Arg ( { name : 'value' , type : graphql . GraphQLString } ) value : string ,
110112 @D . Ctx ( ) context : any ,
111113 ) : Promise < [ string [ ] , number ] > {
112- return [ [ `Hello, ${ value } !` ] , 1 ] ;
114+ const items = [ `Hello, ${ value } !` , `Hello again, ${ value } !` , `Hi, ${ value } !` ] ;
115+ return [ items . slice ( offset , offset + limit ) , items . length ] ;
113116 }
114117 }
115118
@@ -118,11 +121,11 @@ describe('Functional', function () {
118121 @D . Query ( ) query : QueryType ;
119122 }
120123
121- it ( 'resolves @Field with pagination' , async function ( ) {
124+ it ( 'resolves @Field with pagination for first page ' , async function ( ) {
122125 const schema = schemaFactory ( SchemaType ) ;
123126 const result = await graphql . graphql ( schema , `
124127 query {
125- paginated(value: "world") {
128+ paginated(value: "world", offset: 0, limit: 1 ) {
126129 count
127130 nodes
128131 pageInfo {
@@ -132,13 +135,55 @@ describe('Functional', function () {
132135 }
133136 }
134137 ` ) ;
135- assert ( result . data . paginated . count === 1 ) ;
138+ assert ( result . data . paginated . count === 3 ) ;
136139 assert ( result . data . paginated . nodes . length === 1 ) ;
137140 assert ( result . data . paginated . nodes [ 0 ] === 'Hello, world!' ) ;
138- assert ( result . data . paginated . pageInfo . hasNextPage === false ) ;
141+ assert ( result . data . paginated . pageInfo . hasNextPage === true ) ;
139142 assert ( result . data . paginated . pageInfo . hasPreviousPage === false ) ;
140143 } ) ;
141144
145+ it ( 'resolves @Field with pagination middle page' , async function ( ) {
146+ const schema = schemaFactory ( SchemaType ) ;
147+ const result = await graphql . graphql ( schema , `
148+ query {
149+ paginated(value: "world", offset: 1, limit: 1) {
150+ count
151+ nodes
152+ pageInfo {
153+ hasNextPage
154+ hasPreviousPage
155+ }
156+ }
157+ }
158+ ` ) ;
159+ assert ( result . data . paginated . count === 3 ) ;
160+ assert ( result . data . paginated . nodes . length === 1 ) ;
161+ assert ( result . data . paginated . nodes [ 0 ] === 'Hello again, world!' ) ;
162+ assert ( result . data . paginated . pageInfo . hasNextPage === true ) ;
163+ assert ( result . data . paginated . pageInfo . hasPreviousPage === true ) ;
164+ } ) ;
165+
166+ it ( 'resolves @Field with pagination for last page' , async function ( ) {
167+ const schema = schemaFactory ( SchemaType ) ;
168+ const result = await graphql . graphql ( schema , `
169+ query {
170+ paginated(value: "world", offset: 2, limit: 1) {
171+ count
172+ nodes
173+ pageInfo {
174+ hasNextPage
175+ hasPreviousPage
176+ }
177+ }
178+ }
179+ ` ) ;
180+ assert ( result . data . paginated . count === 3 ) ;
181+ assert ( result . data . paginated . nodes . length === 1 ) ;
182+ assert ( result . data . paginated . nodes [ 0 ] === 'Hi, world!' ) ;
183+ assert ( result . data . paginated . pageInfo . hasNextPage === false ) ;
184+ assert ( result . data . paginated . pageInfo . hasPreviousPage === true ) ;
185+ } ) ;
186+
142187 } ) ;
143188
144189 describe ( 'Before Middleware' , function ( ) {
0 commit comments