@@ -36,8 +36,8 @@ describe('objectTypeFactory', function () {
3636 @D . ObjectType ( )
3737 class Obj { @D . Field ( ) title : string ; }
3838 const GQLType : any = objectTypeFactory ( Obj ) ;
39- assert ( GQLType . _typeConfig . name === 'Obj' ) ;
40- assert ( GQLType . _typeConfig . fields . title . type instanceof graphql . GraphQLScalarType ) ;
39+ assert ( GQLType . name === 'Obj' ) ;
40+ assert ( GQLType . getFields ( ) . title . type instanceof graphql . GraphQLScalarType ) ;
4141 } ) ;
4242
4343 it ( 'returns GraphQLInputObjectType with a class annotated by @InputObjectType' , function ( ) {
@@ -62,11 +62,30 @@ describe('objectTypeFactory', function () {
6262 @D . InputObjectType ( )
6363 class Obj { @D . Field ( ) title : string ; @D . Field ( { type : undefined } ) nested : { } ; }
6464 try {
65- const GQLType : any = objectTypeFactory ( Obj , true ) ;
65+ const GQLType = objectTypeFactory ( Obj , true ) ;
66+ GQLType . getFields ( ) ;
6667 assert . fail ( ) ;
6768 } catch ( e ) {
6869 const err = e as SchemaFactoryError ;
6970 assert ( err . type === SchemaFactoryErrorType . NO_FIELD ) ;
7071 }
7172 } ) ;
73+
74+ it ( 'returns GraphQLObjectType if includes circular references' , function ( ) {
75+ @D . ObjectType ( )
76+ class Obj { @D . Field ( ) circle : Obj ; }
77+ const GQLType = objectTypeFactory ( Obj ) ;
78+ assert ( GQLType . name === 'Obj' ) ;
79+ assert ( ( GQLType . getFields ( ) . circle . type as graphql . GraphQLObjectType ) . getFields ( ) . circle . type instanceof graphql . GraphQLObjectType ) ;
80+ } ) ;
81+
82+ it ( 'allows thunk circular dependecies' , function ( ) {
83+ @D . ObjectType ( )
84+ class A { @D . Field ( { type : ( ) => B } ) circle : any ; } // tslint:disable-line:no-use-before-declare
85+ @D . ObjectType ( )
86+ class B { @D . Field ( { type : ( ) => A } ) circle : any ; }
87+ const GQLType = objectTypeFactory ( A ) ;
88+ assert ( GQLType . name === 'A' ) ;
89+ assert ( ( GQLType . getFields ( ) . circle . type as graphql . GraphQLObjectType ) . getFields ( ) . circle . type instanceof graphql . GraphQLObjectType ) ;
90+ } ) ;
7291} ) ;
0 commit comments