11/* @flow */
22/* eslint-disable no-param-reassign */
33
4- import { TypeComposer } from 'graphql-compose' ;
4+ import { schemaComposer , ObjectTypeComposer } from 'graphql-compose' ;
55import { GraphQLSchema , GraphQLList , GraphQLNonNull , graphql } from 'graphql-compose/lib/graphql' ;
66import { composeWithConnection } from '../composeWithConnection' ;
7- import { userTypeComposer , sortOptions } from '../__mocks__/userTypeComposer ' ;
8- import { rootQueryTypeComposer as rootQueryTC } from '../__mocks__/rootQueryTypeComposer ' ;
7+ import { userTC , sortOptions } from '../__mocks__/userTC ' ;
8+ import { rootQueryTC } from '../__mocks__/rootQueryTC ' ;
99
1010describe ( 'composeWithRelay' , ( ) => {
11- const userComposer = composeWithConnection ( userTypeComposer , {
11+ const userComposer = composeWithConnection ( userTC , {
1212 countResolverName : 'count' ,
1313 findResolverName : 'findMany' ,
1414 sort : sortOptions ,
1515 } ) ;
1616
1717 describe ( 'basic checks' , ( ) => {
18- it ( 'should return TypeComposer ' , ( ) => {
19- expect ( userComposer ) . toBeInstanceOf ( TypeComposer ) ;
18+ it ( 'should return ObjectTypeComposer ' , ( ) => {
19+ expect ( userComposer ) . toBeInstanceOf ( ObjectTypeComposer ) ;
2020 } ) ;
2121
22- it ( 'should throw error if first arg is not TypeComposer ' , ( ) => {
22+ it ( 'should throw error if first arg is not ObjectTypeComposer ' , ( ) => {
2323 expect ( ( ) => {
2424 const wrongArgs : any = [ 123 ] ;
2525 composeWithConnection ( ...wrongArgs ) ;
26- } ) . toThrowError ( 'should provide TypeComposer instance' ) ;
26+ } ) . toThrowError ( 'should provide ObjectTypeComposer instance' ) ;
2727 } ) ;
2828
2929 it ( 'should throw error if options are empty' , ( ) => {
3030 expect ( ( ) => {
31- const wrongArgs : any = [ userTypeComposer ] ;
31+ const wrongArgs : any = [ userTC ] ;
3232 composeWithConnection ( ...wrongArgs ) ;
3333 } ) . toThrowError ( 'should provide non-empty options' ) ;
3434 } ) ;
3535
3636 it ( 'should not change `connection` resolver if exists' , ( ) => {
37- let myTC = TypeComposer . create ( 'type Complex { a: String, b: Int }' ) ;
37+ let myTC = schemaComposer . createObjectTC ( 'type Complex { a: String, b: Int }' ) ;
3838 myTC . addResolver ( {
3939 name : 'connection' ,
4040 resolve : ( ) => 'mockData' ,
@@ -48,11 +48,11 @@ describe('composeWithRelay', () => {
4848 } ) ;
4949
5050 expect ( myTC . getResolver ( 'connection' ) ) . toBeTruthy ( ) ;
51- expect ( myTC . getResolver ( 'connection' ) . resolve ( ) ) . toBe ( 'mockData' ) ;
51+ expect ( myTC . getResolver ( 'connection' ) . resolve ( { } ) ) . toBe ( 'mockData' ) ;
5252 } ) ;
5353
5454 it ( 'should add resolver with user-specified name' , ( ) => {
55- let myTC = TypeComposer . create ( 'type CustomComplex { a: String, b: Int }' ) ;
55+ let myTC = schemaComposer . createObjectTC ( 'type CustomComplex { a: String, b: Int }' ) ;
5656 myTC . addResolver ( {
5757 name : 'count' ,
5858 resolve : ( ) => 1 ,
@@ -73,7 +73,7 @@ describe('composeWithRelay', () => {
7373 } ) ;
7474
7575 it ( 'should add two connection resolvers' , ( ) => {
76- let myTC = TypeComposer . create ( 'type CustomComplex { a: String, b: Int }' ) ;
76+ let myTC = schemaComposer . createObjectTC ( 'type CustomComplex { a: String, b: Int }' ) ;
7777 myTC . addResolver ( {
7878 name : 'count' ,
7979 resolve : ( ) => 1 ,
@@ -102,7 +102,7 @@ describe('composeWithRelay', () => {
102102 describe ( 'check `connection` resolver props' , ( ) => {
103103 const rsv = userComposer . getResolver ( 'connection' ) ;
104104 const type : any = rsv . getType ( ) ;
105- const tc = new TypeComposer ( type ) ;
105+ const tc = schemaComposer . createObjectTC ( type ) ;
106106
107107 it ( 'should exists' , ( ) => {
108108 expect ( rsv ) . toBeTruthy ( ) ;
@@ -118,7 +118,7 @@ describe('composeWithRelay', () => {
118118 } ) ;
119119
120120 it ( 'should apply first sort ID_ASC by default' , async ( ) => {
121- rootQueryTC . setField ( 'userConnection' , userTypeComposer . getResolver ( 'connection' ) ) ;
121+ rootQueryTC . setField ( 'userConnection' , userTC . getResolver ( 'connection' ) ) ;
122122 const schema = new GraphQLSchema ( {
123123 query : rootQueryTC . getType ( ) ,
124124 } ) ;
@@ -168,7 +168,7 @@ describe('composeWithRelay', () => {
168168 } ) ;
169169
170170 it ( 'should able to change `sort` on AGE_ID_DESC' , async ( ) => {
171- rootQueryTC . setField ( 'userConnection' , userTypeComposer . getResolver ( 'connection' ) ) ;
171+ rootQueryTC . setField ( 'userConnection' , userTC . getResolver ( 'connection' ) ) ;
172172 const schema = new GraphQLSchema ( {
173173 query : rootQueryTC . getType ( ) ,
174174 } ) ;
@@ -220,7 +220,7 @@ describe('composeWithRelay', () => {
220220
221221 describe ( 'fragments fields projection of graphql-compose' , ( ) => {
222222 it ( 'should return object' , async ( ) => {
223- rootQueryTC . setField ( 'userConnection' , userTypeComposer . getResolver ( 'connection' ) ) ;
223+ rootQueryTC . setField ( 'userConnection' , userTC . getResolver ( 'connection' ) ) ;
224224 const schema = new GraphQLSchema ( {
225225 query : rootQueryTC . getType ( ) ,
226226 } ) ;
@@ -285,7 +285,7 @@ describe('composeWithRelay', () => {
285285
286286 rootQueryTC . setField (
287287 'userConnection' ,
288- userTypeComposer . getResolver ( 'connection' ) . wrapResolve ( next => rp => {
288+ userTC . getResolver ( 'connection' ) . wrapResolve ( next => rp => {
289289 const result = next ( rp ) ;
290290 topResolveParams = rp ;
291291 return result ;
@@ -315,7 +315,7 @@ describe('composeWithRelay', () => {
315315
316316 rootQueryTC . setField (
317317 'userConnection' ,
318- userTypeComposer . getResolver ( 'connection' ) . wrapResolve ( next => rp => {
318+ userTC . getResolver ( 'connection' ) . wrapResolve ( next => rp => {
319319 const result = next ( rp ) ;
320320 topResolveParams = rp ;
321321 return result ;
0 commit comments