1
1
/* @flow */
2
2
/* eslint-disable no-param-reassign */
3
3
4
- import { TypeComposer } from 'graphql-compose' ;
4
+ import { schemaComposer , ObjectTypeComposer } from 'graphql-compose' ;
5
5
import { GraphQLSchema , GraphQLList , GraphQLNonNull , graphql } from 'graphql-compose/lib/graphql' ;
6
6
import { 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 ' ;
9
9
10
10
describe ( 'composeWithRelay' , ( ) => {
11
- const userComposer = composeWithConnection ( userTypeComposer , {
11
+ const userComposer = composeWithConnection ( userTC , {
12
12
countResolverName : 'count' ,
13
13
findResolverName : 'findMany' ,
14
14
sort : sortOptions ,
15
15
} ) ;
16
16
17
17
describe ( 'basic checks' , ( ) => {
18
- it ( 'should return TypeComposer ' , ( ) => {
19
- expect ( userComposer ) . toBeInstanceOf ( TypeComposer ) ;
18
+ it ( 'should return ObjectTypeComposer ' , ( ) => {
19
+ expect ( userComposer ) . toBeInstanceOf ( ObjectTypeComposer ) ;
20
20
} ) ;
21
21
22
- it ( 'should throw error if first arg is not TypeComposer ' , ( ) => {
22
+ it ( 'should throw error if first arg is not ObjectTypeComposer ' , ( ) => {
23
23
expect ( ( ) => {
24
24
const wrongArgs : any = [ 123 ] ;
25
25
composeWithConnection ( ...wrongArgs ) ;
26
- } ) . toThrowError ( 'should provide TypeComposer instance' ) ;
26
+ } ) . toThrowError ( 'should provide ObjectTypeComposer instance' ) ;
27
27
} ) ;
28
28
29
29
it ( 'should throw error if options are empty' , ( ) => {
30
30
expect ( ( ) => {
31
- const wrongArgs : any = [ userTypeComposer ] ;
31
+ const wrongArgs : any = [ userTC ] ;
32
32
composeWithConnection ( ...wrongArgs ) ;
33
33
} ) . toThrowError ( 'should provide non-empty options' ) ;
34
34
} ) ;
35
35
36
36
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 }' ) ;
38
38
myTC . addResolver ( {
39
39
name : 'connection' ,
40
40
resolve : ( ) => 'mockData' ,
@@ -48,11 +48,11 @@ describe('composeWithRelay', () => {
48
48
} ) ;
49
49
50
50
expect ( myTC . getResolver ( 'connection' ) ) . toBeTruthy ( ) ;
51
- expect ( myTC . getResolver ( 'connection' ) . resolve ( ) ) . toBe ( 'mockData' ) ;
51
+ expect ( myTC . getResolver ( 'connection' ) . resolve ( { } ) ) . toBe ( 'mockData' ) ;
52
52
} ) ;
53
53
54
54
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 }' ) ;
56
56
myTC . addResolver ( {
57
57
name : 'count' ,
58
58
resolve : ( ) => 1 ,
@@ -73,7 +73,7 @@ describe('composeWithRelay', () => {
73
73
} ) ;
74
74
75
75
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 }' ) ;
77
77
myTC . addResolver ( {
78
78
name : 'count' ,
79
79
resolve : ( ) => 1 ,
@@ -102,7 +102,7 @@ describe('composeWithRelay', () => {
102
102
describe ( 'check `connection` resolver props' , ( ) => {
103
103
const rsv = userComposer . getResolver ( 'connection' ) ;
104
104
const type : any = rsv . getType ( ) ;
105
- const tc = new TypeComposer ( type ) ;
105
+ const tc = schemaComposer . createObjectTC ( type ) ;
106
106
107
107
it ( 'should exists' , ( ) => {
108
108
expect ( rsv ) . toBeTruthy ( ) ;
@@ -118,7 +118,7 @@ describe('composeWithRelay', () => {
118
118
} ) ;
119
119
120
120
it ( 'should apply first sort ID_ASC by default' , async ( ) => {
121
- rootQueryTC . setField ( 'userConnection' , userTypeComposer . getResolver ( 'connection' ) ) ;
121
+ rootQueryTC . setField ( 'userConnection' , userTC . getResolver ( 'connection' ) ) ;
122
122
const schema = new GraphQLSchema ( {
123
123
query : rootQueryTC . getType ( ) ,
124
124
} ) ;
@@ -168,7 +168,7 @@ describe('composeWithRelay', () => {
168
168
} ) ;
169
169
170
170
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' ) ) ;
172
172
const schema = new GraphQLSchema ( {
173
173
query : rootQueryTC . getType ( ) ,
174
174
} ) ;
@@ -220,7 +220,7 @@ describe('composeWithRelay', () => {
220
220
221
221
describe ( 'fragments fields projection of graphql-compose' , ( ) => {
222
222
it ( 'should return object' , async ( ) => {
223
- rootQueryTC . setField ( 'userConnection' , userTypeComposer . getResolver ( 'connection' ) ) ;
223
+ rootQueryTC . setField ( 'userConnection' , userTC . getResolver ( 'connection' ) ) ;
224
224
const schema = new GraphQLSchema ( {
225
225
query : rootQueryTC . getType ( ) ,
226
226
} ) ;
@@ -285,7 +285,7 @@ describe('composeWithRelay', () => {
285
285
286
286
rootQueryTC . setField (
287
287
'userConnection' ,
288
- userTypeComposer . getResolver ( 'connection' ) . wrapResolve ( next => rp => {
288
+ userTC . getResolver ( 'connection' ) . wrapResolve ( next => rp => {
289
289
const result = next ( rp ) ;
290
290
topResolveParams = rp ;
291
291
return result ;
@@ -315,7 +315,7 @@ describe('composeWithRelay', () => {
315
315
316
316
rootQueryTC . setField (
317
317
'userConnection' ,
318
- userTypeComposer . getResolver ( 'connection' ) . wrapResolve ( next => rp => {
318
+ userTC . getResolver ( 'connection' ) . wrapResolve ( next => rp => {
319
319
const result = next ( rp ) ;
320
320
topResolveParams = rp ;
321
321
return result ;
0 commit comments