@@ -23,7 +23,6 @@ import { reorderFields } from './utils';
2323const { GraphQLInterfaceType } = graphql ;
2424
2525export type Options = {
26- test_disTypes ?: boolean ,
2726 reorderFields ?: boolean | string [ ] , // true order: _id, DKey, DInterfaceFields, DiscriminatorFields
2827 customizationOptions ?: TypeConverterOpts ,
2928} ;
@@ -51,8 +50,7 @@ function setDKeyETCValues(discriminators: Discriminators): any {
5150// then sets this enum type as the discriminator key field type
5251function createAndSetDKeyETC ( dTC : DiscriminatorTypeComposer , discriminators : Discriminators ) {
5352 const DKeyETC = EnumTypeComposer . create ( {
54- name : `EnumDKey${ dTC . getDBaseName ( ) } ${ dTC . getDKey ( ) [ 0 ] . toUpperCase ( ) +
55- dTC . getDKey ( ) . substr ( 1 ) } `,
53+ name : `EnumDKey${ dTC . getTypeName ( ) } ${ dTC . getDKey ( ) [ 0 ] . toUpperCase ( ) + dTC . getDKey ( ) . substr ( 1 ) } ` ,
5654 values : setDKeyETCValues ( discriminators ) ,
5755 } ) ;
5856
@@ -82,7 +80,7 @@ function getBaseTCFieldsWithTypes(baseTC: TypeComposer) {
8280
8381function createDInterface ( baseModelTC : DiscriminatorTypeComposer ) : GraphQLInterfaceType {
8482 return new GraphQLInterfaceType ( {
85- name : `${ baseModelTC . getDBaseName ( ) } Interface` ,
83+ name : `${ baseModelTC . getTypeName ( ) } Interface` ,
8684
8785 resolveType : ( value : any ) => {
8886 const childDName = value [ baseModelTC . getDKey ( ) ] ;
@@ -100,8 +98,6 @@ function createDInterface(baseModelTC: DiscriminatorTypeComposer): GraphQLInterf
10098}
10199
102100export class DiscriminatorTypeComposer extends TypeComposer {
103- modelName : string ;
104-
105101 discriminatorKey : string ;
106102
107103 DKeyETC : EnumTypeComposer ;
@@ -112,8 +108,6 @@ export class DiscriminatorTypeComposer extends TypeComposer {
112108
113109 DInterface : GraphQLInterfaceType ;
114110
115- discriminators : Discriminators ;
116-
117111 childTCs : TypeComposer [ ] ;
118112
119113 constructor ( baseModel : Model , opts ?: any ) {
@@ -131,22 +125,17 @@ export class DiscriminatorTypeComposer extends TypeComposer {
131125
132126 super ( composeWithMongoose ( baseModel , opts . customizationOptions ) . gqType ) ;
133127
134- // !ORDER MATTERS
135128 this . opts = opts ;
136- this . modelName = ( baseModel : any ) . modelName ;
129+ this . childTCs = [ ] ;
137130 this . discriminatorKey = ( baseModel : any ) . schema . get ( 'discriminatorKey' ) || '__t' ;
138131
139- // discriminants and object containing all discriminants with key
140- // key being their DNames
141- this . discriminators = ( baseModel : any ) . discriminators ;
142-
143- this . childTCs = [ ] ;
144132 this . schemaComposer =
145133 opts . customizationOptions && opts . customizationOptions . schemaComposer
146134 ? opts . customizationOptions . schemaComposer
147135 : schemaComposer ;
148- this . setTypeName ( this . modelName ) ;
149- this . DKeyETC = createAndSetDKeyETC ( this , this . discriminators ) ;
136+
137+ // discriminators an object containing all discriminators with key being DNames
138+ this . DKeyETC = createAndSetDKeyETC ( this , ( baseModel : any ) . discriminators ) ;
150139
151140 reorderFields ( this , ( this . opts : any ) . reorderFields , this . discriminatorKey ) ;
152141
@@ -167,10 +156,6 @@ export class DiscriminatorTypeComposer extends TypeComposer {
167156 return this . DKeyETC ;
168157 }
169158
170- getDBaseName ( ) : string {
171- return this . modelName ;
172- }
173-
174159 getDInterface ( ) : GraphQLInterfaceType {
175160 return this . DInterface ;
176161 }
0 commit comments