@@ -15,7 +15,6 @@ type ComposeScalarType = string | GraphQLScalarType;
1515type ComposeOutputType = TypeComposer | ComposeScalarType | EnumTypeComposer | [ ComposeOutputType ] ;
1616
1717export type MongoosePseudoModelT = {
18- _gqcTypeComposer ?: TypeComposer ,
1918 schema : Schema < any > ,
2019} ;
2120
@@ -117,19 +116,21 @@ export function convertModelToGraphQL(
117116) : TypeComposer {
118117 const schemaComposer = sc || globalSchemaComposer ;
119118
120- // if model already has generated TypeComposer early, then return it
121- const modelSchema : any = model . schema ;
122- if ( modelSchema && modelSchema . _gqcTypeComposer ) {
123- return modelSchema . _gqcTypeComposer;
124- }
125-
126119 if ( ! typeName ) {
127120 throw new Error ( 'You provide empty name for type. `name` argument should be non-empty string.' ) ;
128121 }
129122
130- const typeComposer = schemaComposer . getOrCreateTC ( typeName ) ;
123+ // if model already has generated TypeComposer early, then return it
124+ // $FlowFixMe await landing [email protected] or above 125+ if ( schemaComposer . has ( model . schema ) ) {
126+ // $FlowFixMe await landing [email protected] or above 127+ return schemaComposer . getTC ( model . schema ) ;
128+ }
131129
132- modelSchema . _gqcTypeComposer = typeComposer ; // eslint-disable-line no-param-reassign
130+ const typeComposer = schemaComposer . getOrCreateTC ( typeName ) ;
131+ // $FlowFixMe await landing [email protected] or above 132+ schemaComposer . set ( model . schema , typeComposer ) ;
133+ schemaComposer . set ( typeName , typeComposer ) ;
133134
134135 const mongooseFields = getFieldsFromModel ( model ) ;
135136 const graphqlFields = { } ;
@@ -161,7 +162,7 @@ export function convertModelToGraphQL(
161162}
162163
163164export function convertSchemaToGraphQL (
164- schema : Object , // MongooseModelSchemaT, TODO use Model from mongoose_v4.x.x definition when it will be public
165+ schema : Schema < any > ,
165166 typeName : string ,
166167 sc ?: SchemaComposer < any >
167168) : TypeComposer {
@@ -171,15 +172,18 @@ export function convertSchemaToGraphQL(
171172 throw new Error ( 'You provide empty name for type. `name` argument should be non-empty string.' ) ;
172173 }
173174
174- if ( schema . _gqcTypeComposer ) {
175- return schema . _gqcTypeComposer;
175+ // $FlowFixMe await landing [email protected] or above 176+ if ( schemaComposer . has ( schema ) ) {
177+ // $FlowFixMe await landing [email protected] or above 178+ return schemaComposer . getTC ( schema ) ;
176179 }
177180
178181 const tc = convertModelToGraphQL ( { schema } , typeName , schemaComposer ) ;
179182 // also generate InputType
180183 tc . getInputTypeComposer ( ) ;
181184
182- schema . _gqcTypeComposer = tc ; // eslint-disable-line
185+ // $FlowFixMe await landing [email protected] or above 186+ schemaComposer . set ( schema , tc ) ;
183187 return tc ;
184188}
185189
0 commit comments