11/* @flow */
22
3- import { schemaComposer } from 'graphql-compose' ;
3+ import { schemaComposer , ObjectTypeComposer } from 'graphql-compose' ;
44import {
55 GraphQLNonNull ,
6- GraphQLObjectType ,
76 getNamedType ,
87 GraphQLInt ,
98 GraphQLString ,
109 GraphQLList ,
1110} from 'graphql-compose/lib/graphql' ;
1211import { userTC } from '../../__mocks__/userTC' ;
1312import { prepareEdgeType , prepareConnectionType } from '../connectionType' ;
14- import PageInfoType from '../pageInfoType' ;
1513
1614describe ( 'types/connectionType.js' , ( ) => {
1715 describe ( 'prepareEdgeType()' , ( ) => {
18- it ( 'should return GraphQLObjectType ' , ( ) => {
19- expect ( prepareEdgeType ( userTC ) ) . toBeInstanceOf ( GraphQLObjectType ) ;
16+ it ( 'should return ComposeObjectType ' , ( ) => {
17+ expect ( prepareEdgeType ( userTC ) ) . toBeInstanceOf ( ObjectTypeComposer ) ;
2018 } ) ;
2119
2220 it ( 'should have name ending with `Edge`' , ( ) => {
23- expect ( prepareEdgeType ( userTC ) . name ) . toBe ( 'UserEdge' ) ;
21+ expect ( prepareEdgeType ( userTC ) . getTypeName ( ) ) . toBe ( 'UserEdge' ) ;
2422 } ) ;
2523
2624 it ( 'should have field `node` with provided Type' , ( ) => {
@@ -38,11 +36,6 @@ describe('types/connectionType.js', () => {
3836 expect ( cursor ) . toBe ( GraphQLString ) ;
3937 } ) ;
4038
41- it ( 'should have `ofType` property (like GraphQLList, GraphQLNonNull)' , ( ) => {
42- const edgeType : any = prepareEdgeType ( userTC ) ;
43- expect ( edgeType . ofType ) . toEqual ( userTC . getType ( ) ) ;
44- } ) ;
45-
4639 it ( 'should return same type for same Type in ObjectTypeComposer' , ( ) => {
4740 const t1 = prepareEdgeType ( userTC ) ;
4841 const t2 = prepareEdgeType ( userTC ) ;
@@ -51,31 +44,33 @@ describe('types/connectionType.js', () => {
5144 } ) ;
5245
5346 describe ( 'prepareConnectionType()' , ( ) => {
54- it ( 'should return GraphQLObjectType ' , ( ) => {
55- expect ( prepareConnectionType ( userTC ) ) . toBeInstanceOf ( GraphQLObjectType ) ;
47+ it ( 'should return ComposeObjectType ' , ( ) => {
48+ expect ( prepareConnectionType ( userTC ) ) . toBeInstanceOf ( ObjectTypeComposer ) ;
5649 } ) ;
5750
58- it ( 'should return the same GraphQLObjectType object when called again' , ( ) => {
51+ it ( 'should return the same ComposeObjectType object when called again' , ( ) => {
5952 const firstConnectionType = prepareConnectionType ( userTC ) ;
6053 const secondConnectionType = prepareConnectionType ( userTC ) ;
61- expect ( firstConnectionType ) . toBeInstanceOf ( GraphQLObjectType ) ;
54+ expect ( firstConnectionType ) . toBeInstanceOf ( ObjectTypeComposer ) ;
6255 expect ( firstConnectionType ) . toBe ( secondConnectionType ) ;
6356 } ) ;
6457
65- it ( 'should return a separate GraphQLObjectType with a different name' , ( ) => {
58+ it ( 'should return a separate ComposeObjectType with a different name' , ( ) => {
6659 const connectionType = prepareConnectionType ( userTC ) ;
6760 const otherConnectionType = prepareConnectionType ( userTC , 'otherConnection' ) ;
68- expect ( connectionType ) . toBeInstanceOf ( GraphQLObjectType ) ;
69- expect ( otherConnectionType ) . toBeInstanceOf ( GraphQLObjectType ) ;
61+ expect ( connectionType ) . toBeInstanceOf ( ObjectTypeComposer ) ;
62+ expect ( otherConnectionType ) . toBeInstanceOf ( ObjectTypeComposer ) ;
7063 expect ( connectionType ) . not . toBe ( otherConnectionType ) ;
7164 } ) ;
7265
7366 it ( 'should have name ending with `Connection`' , ( ) => {
74- expect ( prepareConnectionType ( userTC ) . name ) . toBe ( 'UserConnection' ) ;
67+ expect ( prepareConnectionType ( userTC ) . getTypeName ( ) ) . toBe ( 'UserConnection' ) ;
7568 } ) ;
7669
7770 it ( 'should have name ending with `OtherConnection` when passed lowercase otherConnection' , ( ) => {
78- expect ( prepareConnectionType ( userTC , 'otherConnection' ) . name ) . toBe ( 'UserOtherConnection' ) ;
71+ expect ( prepareConnectionType ( userTC , 'otherConnection' ) . getTypeName ( ) ) . toBe (
72+ 'UserOtherConnection'
73+ ) ;
7974 } ) ;
8075
8176 it ( 'should have field `count` with provided Type' , ( ) => {
@@ -88,9 +83,7 @@ describe('types/connectionType.js', () => {
8883 it ( 'should have field `pageInfo` with GraphQLNonNull(PageInfoType)' , ( ) => {
8984 const tc = schemaComposer . createObjectTC ( prepareConnectionType ( userTC ) ) ;
9085 expect ( tc . getFieldType ( 'pageInfo' ) ) . toBeInstanceOf ( GraphQLNonNull ) ;
91-
92- const pageInfo = getNamedType ( tc . getFieldType ( 'pageInfo' ) ) ;
93- expect ( pageInfo ) . toBe ( PageInfoType ) ;
86+ expect ( tc . getField ( 'pageInfo' ) . type . getTypeName ( ) ) . toBe ( 'PageInfo!' ) ;
9487 } ) ;
9588
9689 it ( 'should have field `edges` with GraphQLList(EdgeType)' , ( ) => {
@@ -103,13 +96,6 @@ describe('types/connectionType.js', () => {
10396 expect ( edges . name ) . toEqual ( 'UserEdge' ) ;
10497 } ) ;
10598
106- it ( 'should have `ofType` property (like GraphQLList, GraphQLNonNull)' , ( ) => {
107- // this behavior needed for `graphql-compose` module in `projection` helper
108- // otherwise it incorrectly construct projectionMapper for tricky fields
109- const connectionType : any = prepareConnectionType ( userTC ) ;
110- expect ( connectionType . ofType ) . toEqual ( userTC . getType ( ) ) ;
111- } ) ;
112-
11399 it ( 'should return same type for same Type in ObjectTypeComposer' , ( ) => {
114100 const t1 = prepareConnectionType ( userTC ) ;
115101 const t2 = prepareConnectionType ( userTC ) ;
0 commit comments