@@ -16,6 +16,7 @@ describe('composeWithRelay', () => {
1616 describe ( 'basic checks' , ( ) => {
1717 it ( 'should return ObjectTypeComposer' , ( ) => {
1818 expect ( userComposer ) . toBeInstanceOf ( ObjectTypeComposer ) ;
19+ expect ( userComposer ) . toBe ( UserTC ) ;
1920 } ) ;
2021
2122 it ( 'should throw error if first arg is not ObjectTypeComposer' , ( ) => {
@@ -165,8 +166,8 @@ describe('composeWithRelay', () => {
165166 } ) ;
166167
167168 it ( 'should pass `countResolveParams` to top resolverParams' , async ( ) => {
169+ // first build
168170 let topResolveParams : any = { } ;
169-
170171 schemaComposer . Query . setField (
171172 'userPagination' ,
172173 UserTC . getResolver ( 'pagination' ) . wrapResolve ( next => rp => {
@@ -181,13 +182,41 @@ describe('composeWithRelay', () => {
181182 count
182183 }
183184 }` ;
184- await graphql ( schema , query ) ;
185-
185+ const res = await graphql ( schema , query ) ;
186+ expect ( res ) . toEqual ( { data : { userPagination : { count : 15 } } } ) ;
186187 expect ( Object . keys ( topResolveParams . countResolveParams ) ) . toEqual (
187188 expect . arrayContaining ( [ 'source' , 'args' , 'context' , 'info' , 'projection' ] )
188189 ) ;
189190 expect ( topResolveParams . countResolveParams . args ) . toEqual ( {
190191 filter : { age : 45 } ,
192+ perPage : 5 ,
193+ } ) ;
194+
195+ // second build
196+ let topResolveParams2 : any = { } ;
197+ schemaComposer . Query . setField (
198+ 'userPagination' ,
199+ UserTC . getResolver ( 'pagination' ) . wrapResolve ( next => rp => {
200+ const result = next ( rp ) ;
201+ topResolveParams2 = rp ;
202+ return result ;
203+ } )
204+ ) ;
205+
206+ const schema2 = schemaComposer . buildSchema ( ) ;
207+ const query2 = `{
208+ userPagination(filter: { age: 333 }) {
209+ count
210+ }
211+ }` ;
212+ const res2 = await graphql ( schema2 , query2 ) ;
213+ expect ( res2 ) . toEqual ( { data : { userPagination : { count : 15 } } } ) ;
214+ expect ( Object . keys ( topResolveParams2 . countResolveParams ) ) . toEqual (
215+ expect . arrayContaining ( [ 'source' , 'args' , 'context' , 'info' , 'projection' ] )
216+ ) ;
217+ expect ( topResolveParams2 . countResolveParams . args ) . toEqual ( {
218+ filter : { age : 333 } ,
219+ perPage : 5 ,
191220 } ) ;
192221 } ) ;
193222
@@ -204,18 +233,19 @@ describe('composeWithRelay', () => {
204233 ) ;
205234 const schema = schemaComposer . buildSchema ( ) ;
206235 const query = `{
207- userPagination(filter: { age: 45 }) {
236+ userPagination(filter: { age: 55 }) {
208237 count
209238 }
210239 }` ;
211- await graphql ( schema , query ) ;
240+ const res = await graphql ( schema , query ) ;
241+ expect ( res ) . toEqual ( { data : { userPagination : { count : 15 } } } ) ;
212242
213243 expect ( Object . keys ( topResolveParams . findManyResolveParams ) ) . toEqual (
214244 expect . arrayContaining ( [ 'source' , 'args' , 'context' , 'info' , 'projection' ] )
215245 ) ;
216246
217247 expect ( topResolveParams . findManyResolveParams . args ) . toEqual ( {
218- filter : { age : 45 } ,
248+ filter : { age : 55 } ,
219249 limit : 6 ,
220250 perPage : 5 ,
221251 } ) ;
0 commit comments