88import { TypeComposer } from 'graphql-compose' ;
99import { composeWithConnection } from '../composeWithConnection' ;
1010import { userTypeComposer , sortOptions } from '../__mocks__/userTypeComposer' ;
11- import { rootQueryTypeComposer } from '../__mocks__/rootQueryTypeComposer' ;
11+ import { rootQueryTypeComposer as rootQueryTC } from '../__mocks__/rootQueryTypeComposer' ;
1212
1313
1414describe ( 'composeWithRelay' , ( ) => {
@@ -34,11 +34,11 @@ describe('composeWithRelay', () => {
3434 } ) ;
3535
3636 it ( 'should apply first sort ID_ASC by default' , async ( ) => {
37- rootQueryTypeComposer . addField ( 'userConnection' ,
37+ rootQueryTC . addField ( 'userConnection' ,
3838 userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( )
3939 ) ;
4040 const schema = new GraphQLSchema ( {
41- query : rootQueryTypeComposer . getType ( ) ,
41+ query : rootQueryTC . getType ( ) ,
4242 } ) ;
4343 const query = `{
4444 userConnection(last: 3) {
@@ -86,11 +86,11 @@ describe('composeWithRelay', () => {
8686 } ) ;
8787
8888 it ( 'should able to change `sort` on AGE_ID_DESC' , async ( ) => {
89- rootQueryTypeComposer . addField ( 'userConnection' ,
89+ rootQueryTC . addField ( 'userConnection' ,
9090 userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( )
9191 ) ;
9292 const schema = new GraphQLSchema ( {
93- query : rootQueryTypeComposer . getType ( ) ,
93+ query : rootQueryTC . getType ( ) ,
9494 } ) ;
9595 const query = `{
9696 userConnection(first: 3, sort: AGE_ID_DESC) {
@@ -140,11 +140,11 @@ describe('composeWithRelay', () => {
140140
141141 describe ( 'fragments fields projection of graphql-compose' , ( ) => {
142142 it ( 'should return object' , async ( ) => {
143- rootQueryTypeComposer . addField ( 'userConnection' ,
143+ rootQueryTC . addField ( 'userConnection' ,
144144 userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( )
145145 ) ;
146146 const schema = new GraphQLSchema ( {
147- query : rootQueryTypeComposer . getType ( ) ,
147+ query : rootQueryTC . getType ( ) ,
148148 } ) ;
149149 const query = `{
150150 userConnection(first: 1) {
@@ -201,4 +201,63 @@ describe('composeWithRelay', () => {
201201 } ) ;
202202 } ) ;
203203 } ) ;
204+
205+ it ( 'should pass `countResolveParams` to top resolverParams' , async ( ) => {
206+ let topResolveParams ;
207+
208+ rootQueryTC . addField ( 'userConnection' ,
209+ userTypeComposer
210+ . getResolver ( 'connection' )
211+ . wrapResolve ( ( next ) => ( rp ) => {
212+ const result = next ( rp ) ;
213+ topResolveParams = rp ;
214+ return result ;
215+ } )
216+ . getFieldConfig ( )
217+ ) ;
218+ const schema = new GraphQLSchema ( {
219+ query : rootQueryTC . getType ( ) ,
220+ } ) ;
221+ const query = `{
222+ userConnection(first: 1, filter: { age: 45 }) {
223+ count
224+ }
225+ }` ;
226+ const result = await graphql ( schema , query ) ;
227+ expect ( topResolveParams ) . has . property ( 'countResolveParams' ) ;
228+ expect ( topResolveParams . countResolveParams )
229+ . to . contain . all . keys ( [ 'source' , 'args' , 'context' , 'info' , 'projection' ] ) ;
230+ expect ( topResolveParams . countResolveParams . args )
231+ . deep . equal ( { filter : { age : 45 } } ) ;
232+ } ) ;
233+
234+
235+ it ( 'should pass `findManyResolveParams` to top resolverParams' , async ( ) => {
236+ let topResolveParams ;
237+
238+ rootQueryTC . addField ( 'userConnection' ,
239+ userTypeComposer
240+ . getResolver ( 'connection' )
241+ . wrapResolve ( ( next ) => ( rp ) => {
242+ const result = next ( rp ) ;
243+ topResolveParams = rp ;
244+ return result ;
245+ } )
246+ . getFieldConfig ( )
247+ ) ;
248+ const schema = new GraphQLSchema ( {
249+ query : rootQueryTC . getType ( ) ,
250+ } ) ;
251+ const query = `{
252+ userConnection(first: 1, filter: { age: 45 }) {
253+ count
254+ }
255+ }` ;
256+ const result = await graphql ( schema , query ) ;
257+ expect ( topResolveParams ) . has . property ( 'findManyResolveParams' ) ;
258+ expect ( topResolveParams . findManyResolveParams )
259+ . to . contain . all . keys ( [ 'source' , 'args' , 'context' , 'info' , 'projection' ] ) ;
260+ expect ( topResolveParams . findManyResolveParams . args )
261+ . deep . equal ( { filter : { age : 45 } , limit : 2 , sort : { id : 1 } } ) ;
262+ } ) ;
204263} ) ;
0 commit comments