@@ -135,34 +135,98 @@ describe('schemaFactory', function() {
135135 describe ( 'Pagination' , function ( ) {
136136
137137 it ( 'returns a GraphQL Pagination object with custom @OrberBy fields' , async function ( ) {
138+ @D . ObjectType ( )
139+ class Obj {
140+ @D . Description ( 'a field' )
141+ @D . Field ( { type : GraphQLString } )
142+ aField : string ;
143+ }
138144
139- @D . ObjectType ( )
140- class Obj {
141- @D . Description ( 'a field' )
142- @D . Field ( { type : GraphQLString } )
143- aField : string ;
144- }
145+ @D . ObjectType ( ) class Query {
146+ @D . Field ( { type : Obj } )
147+ @D . Pagination ( )
148+ async paginate (
149+ @D . OrderBy ( { extraColumns : [ 'extraField' ] } ) orderBy ?: OrderByItem [ ] ,
150+ ) : Promise < [ Obj , number ] > {
151+ return [ { aField : null } , 0 ] ;
152+ }
153+ }
154+ @D . Schema ( ) class Schema { @D . Query ( ) query : Query ; }
155+ const schema = schemaFactory ( Schema ) ;
156+ const ast = parse ( `
157+ query {
158+ paginate(orderBy: [{sort: aField, direction: ASC}, {sort: extraField, direction: DESC}]) {
159+ count
160+ }
161+ }` ) ;
162+ assert . deepEqual ( validate ( schema , ast ) , [ ] ) ;
163+ } ) ;
145164
146- @D . ObjectType ( ) class Query {
147- @D . Field ( { type : Obj } )
148- @D . Pagination ( )
149- async paginate (
150- @D . OrderBy ( [ 'extraField' ] ) orderBy ?: OrderByItem [ ] ,
151- ) : Promise < [ Obj , number ] > {
152- return [ { aField : null } , 0 ] ;
153- }
165+ it ( 'returns a GraphQL Pagination object with custom @OrberBy fields (backwards compatibility)' , async function ( ) {
166+ @D . ObjectType ( )
167+ class Obj {
168+ @D . Description ( 'a field' )
169+ @D . Field ( { type : GraphQLString } )
170+ aField : string ;
171+ }
172+
173+ @D . ObjectType ( ) class Query {
174+ @D . Field ( { type : Obj } )
175+ @D . Pagination ( )
176+ async paginate (
177+ @D . OrderBy ( [ 'extraField' ] ) orderBy ?: OrderByItem [ ] ,
178+ ) : Promise < [ Obj , number ] > {
179+ return [ { aField : null } , 0 ] ;
180+ }
181+ }
182+ @D . Schema ( ) class Schema { @D . Query ( ) query : Query ; }
183+ const schema = schemaFactory ( Schema ) ;
184+ const ast = parse ( `
185+ query {
186+ paginate(orderBy: [{sort: aField, direction: ASC}, {sort: extraField, direction: DESC}]) {
187+ count
188+ }
189+ }` ) ;
190+ assert . deepEqual ( validate ( schema , ast ) , [ ] ) ;
191+ } ) ;
192+
193+ it ( 'returns a GraphQL Pagination object with custom @OrberBy fields ignoring schema fields' , async function ( ) {
194+
195+ @D . ObjectType ( )
196+ class Obj {
197+ @D . Description ( 'a field' )
198+ @D . Field ( { type : GraphQLString } )
199+ aField : string ;
200+ }
201+
202+ @D . ObjectType ( ) class Query {
203+ @D . Field ( { type : Obj } )
204+ @D . Pagination ( )
205+ async paginate (
206+ @D . OrderBy ( { extraColumns : [ 'extraField' ] , shouldIgnoreSchemaFields : true } ) orderBy ?: OrderByItem [ ] ,
207+ ) : Promise < [ Obj , number ] > {
208+ return [ { aField : null } , 0 ] ;
154209 }
155- @D . Schema ( ) class Schema { @D . Query ( ) query : Query ; }
156- const schema = schemaFactory ( Schema ) ;
157- const ast = parse ( `
158- query {
159- paginate(orderBy: [{sort: aField, direction: ASC}, {sort: extraField, direction: DESC}]) {
160- count
161- }
162- }` ) ;
163- assert . deepEqual ( validate ( schema , ast ) , [ ] ) ;
164- } ) ;
210+ }
211+ @D . Schema ( ) class Schema { @D . Query ( ) query : Query ; }
212+ const schema = schemaFactory ( Schema ) ;
213+ const astToIgnore = parse ( `
214+ query {
215+ paginate(orderBy: [{sort: extraField, direction: DESC}]) {
216+ count
217+ }
218+ }` ) ;
219+ const astToError = parse ( `
220+ query {
221+ paginate(orderBy: [{sort: aField, direction: ASC}, {sort: extraField, direction: DESC}]) {
222+ count
223+ }
224+ }` ) ;
225+ assert . deepEqual ( validate ( schema , astToIgnore ) , [ ] , 'should ignore schema fields' ) ;
226+ assert . equal ( validate ( schema , astToError ) . length , 1 , 'should error if an schema fields is provided' ) ;
165227
166228 } ) ;
167229
230+ } ) ;
231+
168232} ) ;
0 commit comments