11/* eslint-disable no-param-reassign */
22
33import { expect } from 'chai' ;
4- import {
5- graphql ,
6- GraphQLSchema ,
7- GraphQLList ,
8- } from 'graphql' ;
4+ import { graphql , GraphQLSchema , GraphQLList } from 'graphql' ;
95import { TypeComposer } from 'graphql-compose' ;
106import { composeWithConnection } from '../composeWithConnection' ;
117import { userTypeComposer , sortOptions } from '../__mocks__/userTypeComposer' ;
128import { rootQueryTypeComposer as rootQueryTC } from '../__mocks__/rootQueryTypeComposer' ;
139
14-
1510describe ( 'composeWithRelay' , ( ) => {
1611 const userComposer = composeWithConnection ( userTypeComposer , {
1712 countResolverName : 'count' ,
@@ -29,15 +24,16 @@ describe('composeWithRelay', () => {
2924 } ) ;
3025
3126 it ( 'should throw error if options are empty' , ( ) => {
32- expect ( ( ) => composeWithConnection ( userTypeComposer ) )
33- . to . throw ( 'should provide non-empty options' ) ;
27+ expect ( ( ) => composeWithConnection ( userTypeComposer ) ) . to . throw (
28+ 'should provide non-empty options' ,
29+ ) ;
3430 } ) ;
3531
3632 it ( 'should not change `connection` resolver if exists' , ( ) => {
3733 let myTC = TypeComposer . create ( 'type Complex { a: String, b: Int }' ) ;
3834 myTC . addResolver ( {
3935 name : 'connection' ,
40- resolve : ( rp ) => 'mockData'
36+ resolve : ( ) => 'mockData' ,
4137 } ) ;
4238
4339 // try ovewrite `connection` resolver
@@ -69,8 +65,9 @@ describe('composeWithRelay', () => {
6965 } ) ;
7066
7167 it ( 'should apply first sort ID_ASC by default' , async ( ) => {
72- rootQueryTC . setField ( 'userConnection' ,
73- userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( )
68+ rootQueryTC . setField (
69+ 'userConnection' ,
70+ userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( ) ,
7471 ) ;
7572 const schema = new GraphQLSchema ( {
7673 query : rootQueryTC . getType ( ) ,
@@ -94,35 +91,35 @@ describe('composeWithRelay', () => {
9491 }
9592 }` ;
9693 const result = await graphql ( schema , query ) ;
97- expect ( result )
98- . deep . property ( 'data.userConnection' )
99- . deep . equals ( {
100- count : 15 ,
101- pageInfo :
102- { startCursor : 'eyJpZCI6MTN9' ,
103- endCursor : 'eyJpZCI6MTV9' ,
104- hasPreviousPage : true ,
105- hasNextPage : false } ,
106- edges : [
107- {
108- cursor : 'eyJpZCI6MTN9' ,
109- node : { id : 13 , name : 'user13' } ,
110- } ,
111- {
112- cursor : 'eyJpZCI6MTR9' ,
113- node : { id : 14 , name : 'user14' } ,
114- } ,
115- {
116- cursor : 'eyJpZCI6MTV9' ,
117- node : { id : 15 , name : 'user15' } ,
118- } ,
119- ] ,
120- } ) ;
94+ expect ( result ) . nested . property ( 'data.userConnection' ) . deep . equals ( {
95+ count : 15 ,
96+ pageInfo : {
97+ startCursor : 'eyJpZCI6MTN9' ,
98+ endCursor : 'eyJpZCI6MTV9' ,
99+ hasPreviousPage : true ,
100+ hasNextPage : false ,
101+ } ,
102+ edges : [
103+ {
104+ cursor : 'eyJpZCI6MTN9' ,
105+ node : { id : 13 , name : 'user13' } ,
106+ } ,
107+ {
108+ cursor : 'eyJpZCI6MTR9' ,
109+ node : { id : 14 , name : 'user14' } ,
110+ } ,
111+ {
112+ cursor : 'eyJpZCI6MTV9' ,
113+ node : { id : 15 , name : 'user15' } ,
114+ } ,
115+ ] ,
116+ } ) ;
121117 } ) ;
122118
123119 it ( 'should able to change `sort` on AGE_ID_DESC' , async ( ) => {
124- rootQueryTC . setField ( 'userConnection' ,
125- userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( )
120+ rootQueryTC . setField (
121+ 'userConnection' ,
122+ userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( ) ,
126123 ) ;
127124 const schema = new GraphQLSchema ( {
128125 query : rootQueryTC . getType ( ) ,
@@ -147,36 +144,36 @@ describe('composeWithRelay', () => {
147144 }
148145 }` ;
149146 const result = await graphql ( schema , query ) ;
150- expect ( result )
151- . deep . property ( 'data.userConnection' )
152- . deep . equals ( {
153- count : 15 ,
154- pageInfo :
155- { startCursor : 'eyJhZ2UiOjQ5LCJpZCI6MTF9' ,
156- endCursor : 'eyJhZ2UiOjQ3LCJpZCI6MTJ9' ,
157- hasPreviousPage : false ,
158- hasNextPage : true } ,
159- edges : [
160- {
161- cursor : 'eyJhZ2UiOjQ5LCJpZCI6MTF9' ,
162- node : { id : 11 , name : 'user11' , age : 49 } ,
163- } ,
164- {
165- cursor : 'eyJhZ2UiOjQ5LCJpZCI6MTB9' ,
166- node : { id : 10 , name : 'user10' , age : 49 } ,
167- } ,
168- {
169- cursor : 'eyJhZ2UiOjQ3LCJpZCI6MTJ9' ,
170- node : { id : 12 , name : 'user12' , age : 47 } ,
171- } ,
172- ] ,
173- } ) ;
147+ expect ( result ) . nested . property ( 'data.userConnection' ) . deep . equals ( {
148+ count : 15 ,
149+ pageInfo : {
150+ startCursor : 'eyJhZ2UiOjQ5LCJpZCI6MTF9' ,
151+ endCursor : 'eyJhZ2UiOjQ3LCJpZCI6MTJ9' ,
152+ hasPreviousPage : false ,
153+ hasNextPage : true ,
154+ } ,
155+ edges : [
156+ {
157+ cursor : 'eyJhZ2UiOjQ5LCJpZCI6MTF9' ,
158+ node : { id : 11 , name : 'user11' , age : 49 } ,
159+ } ,
160+ {
161+ cursor : 'eyJhZ2UiOjQ5LCJpZCI6MTB9' ,
162+ node : { id : 10 , name : 'user10' , age : 49 } ,
163+ } ,
164+ {
165+ cursor : 'eyJhZ2UiOjQ3LCJpZCI6MTJ9' ,
166+ node : { id : 12 , name : 'user12' , age : 47 } ,
167+ } ,
168+ ] ,
169+ } ) ;
174170 } ) ;
175171
176172 describe ( 'fragments fields projection of graphql-compose' , ( ) => {
177173 it ( 'should return object' , async ( ) => {
178- rootQueryTC . setField ( 'userConnection' ,
179- userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( )
174+ rootQueryTC . setField (
175+ 'userConnection' ,
176+ userTypeComposer . getResolver ( 'connection' ) . getFieldConfig ( ) ,
180177 ) ;
181178 const schema = new GraphQLSchema ( {
182179 query : rootQueryTC . getType ( ) ,
@@ -240,15 +237,16 @@ describe('composeWithRelay', () => {
240237 it ( 'should pass `countResolveParams` to top resolverParams' , async ( ) => {
241238 let topResolveParams ;
242239
243- rootQueryTC . setField ( 'userConnection' ,
240+ rootQueryTC . setField (
241+ 'userConnection' ,
244242 userTypeComposer
245243 . getResolver ( 'connection' )
246- . wrapResolve ( ( next ) => ( rp ) => {
244+ . wrapResolve ( next => ( rp ) => {
247245 const result = next ( rp ) ;
248246 topResolveParams = rp ;
249247 return result ;
250248 } )
251- . getFieldConfig ( )
249+ . getFieldConfig ( ) ,
252250 ) ;
253251 const schema = new GraphQLSchema ( {
254252 query : rootQueryTC . getType ( ) ,
@@ -258,27 +256,31 @@ describe('composeWithRelay', () => {
258256 count
259257 }
260258 }` ;
261- const result = await graphql ( schema , query ) ;
259+ await graphql ( schema , query ) ;
262260 expect ( topResolveParams ) . has . property ( 'countResolveParams' ) ;
263- expect ( topResolveParams . countResolveParams )
264- . to . contain . all . keys ( [ 'source' , 'args' , 'context' , 'info' , 'projection' ] ) ;
265- expect ( topResolveParams . countResolveParams . args )
266- . deep . equal ( { filter : { age : 45 } } ) ;
261+ expect ( topResolveParams . countResolveParams ) . to . contain . all . keys ( [
262+ 'source' ,
263+ 'args' ,
264+ 'context' ,
265+ 'info' ,
266+ 'projection' ,
267+ ] ) ;
268+ expect ( topResolveParams . countResolveParams . args ) . deep . equal ( { filter : { age : 45 } } ) ;
267269 } ) ;
268270
269-
270271 it ( 'should pass `findManyResolveParams` to top resolverParams' , async ( ) => {
271272 let topResolveParams ;
272273
273- rootQueryTC . setField ( 'userConnection' ,
274+ rootQueryTC . setField (
275+ 'userConnection' ,
274276 userTypeComposer
275277 . getResolver ( 'connection' )
276- . wrapResolve ( ( next ) => ( rp ) => {
278+ . wrapResolve ( next => ( rp ) => {
277279 const result = next ( rp ) ;
278280 topResolveParams = rp ;
279281 return result ;
280282 } )
281- . getFieldConfig ( )
283+ . getFieldConfig ( ) ,
282284 ) ;
283285 const schema = new GraphQLSchema ( {
284286 query : rootQueryTC . getType ( ) ,
@@ -288,11 +290,20 @@ describe('composeWithRelay', () => {
288290 count
289291 }
290292 }` ;
291- const result = await graphql ( schema , query ) ;
293+ await graphql ( schema , query ) ;
292294 expect ( topResolveParams ) . has . property ( 'findManyResolveParams' ) ;
293- expect ( topResolveParams . findManyResolveParams )
294- . to . contain . all . keys ( [ 'source' , 'args' , 'context' , 'info' , 'projection' ] ) ;
295- expect ( topResolveParams . findManyResolveParams . args )
296- . deep . equal ( { filter : { age : 45 } , limit : 2 , sort : { id : 1 } , first : 1 } ) ;
295+ expect ( topResolveParams . findManyResolveParams ) . to . contain . all . keys ( [
296+ 'source' ,
297+ 'args' ,
298+ 'context' ,
299+ 'info' ,
300+ 'projection' ,
301+ ] ) ;
302+ expect ( topResolveParams . findManyResolveParams . args ) . deep . equal ( {
303+ filter : { age : 45 } ,
304+ limit : 2 ,
305+ sort : { id : 1 } ,
306+ first : 1 ,
307+ } ) ;
297308 } ) ;
298309} ) ;
0 commit comments