8
8
import { TypeComposer } from 'graphql-compose' ;
9
9
import { composeWithConnection } from '../composeWithConnection' ;
10
10
import { userTypeComposer , sortOptions } from '../__mocks__/userTypeComposer' ;
11
- import { rootQueryTypeComposer } from '../__mocks__/rootQueryTypeComposer' ;
11
+ import { rootQueryTypeComposer as rootQueryTC } from '../__mocks__/rootQueryTypeComposer' ;
12
12
13
13
14
14
describe ( 'composeWithRelay' , ( ) => {
@@ -34,11 +34,11 @@ describe('composeWithRelay', () => {
34
34
} ) ;
35
35
36
36
it ( 'should apply first sort ID_ASC by default' , async ( ) => {
37
- rootQueryTypeComposer . addField ( 'userConnection' ,
37
+ rootQueryTC . addField ( 'userConnection' ,
38
38
userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( )
39
39
) ;
40
40
const schema = new GraphQLSchema ( {
41
- query : rootQueryTypeComposer . getType ( ) ,
41
+ query : rootQueryTC . getType ( ) ,
42
42
} ) ;
43
43
const query = `{
44
44
userConnection(last: 3) {
@@ -86,11 +86,11 @@ describe('composeWithRelay', () => {
86
86
} ) ;
87
87
88
88
it ( 'should able to change `sort` on AGE_ID_DESC' , async ( ) => {
89
- rootQueryTypeComposer . addField ( 'userConnection' ,
89
+ rootQueryTC . addField ( 'userConnection' ,
90
90
userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( )
91
91
) ;
92
92
const schema = new GraphQLSchema ( {
93
- query : rootQueryTypeComposer . getType ( ) ,
93
+ query : rootQueryTC . getType ( ) ,
94
94
} ) ;
95
95
const query = `{
96
96
userConnection(first: 3, sort: AGE_ID_DESC) {
@@ -140,11 +140,11 @@ describe('composeWithRelay', () => {
140
140
141
141
describe ( 'fragments fields projection of graphql-compose' , ( ) => {
142
142
it ( 'should return object' , async ( ) => {
143
- rootQueryTypeComposer . addField ( 'userConnection' ,
143
+ rootQueryTC . addField ( 'userConnection' ,
144
144
userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( )
145
145
) ;
146
146
const schema = new GraphQLSchema ( {
147
- query : rootQueryTypeComposer . getType ( ) ,
147
+ query : rootQueryTC . getType ( ) ,
148
148
} ) ;
149
149
const query = `{
150
150
userConnection(first: 1) {
@@ -201,4 +201,63 @@ describe('composeWithRelay', () => {
201
201
} ) ;
202
202
} ) ;
203
203
} ) ;
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
+ } ) ;
204
263
} ) ;
0 commit comments