@@ -191,8 +191,11 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
191191
192192 EnumTypeDefinition ( node : EnumTypeDefinitionNode ) : string | null {
193193 const enumName = node . name . value ;
194- if ( ! this . _usedNamedInputTypes [ enumName ] || this . config . importSchemaTypesFrom ) {
195- return null ;
194+ if (
195+ ! this . _usedNamedInputTypes [ enumName ] || // If not used...
196+ this . config . importSchemaTypesFrom // ... Or, is imported from a shared file
197+ ) {
198+ return null ; // ... then, don't generate in this file
196199 }
197200
198201 return convertSchemaEnumToDeclarationBlockString ( {
@@ -216,19 +219,28 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
216219
217220 InputObjectTypeDefinition ( node : InputObjectTypeDefinitionNode ) : string | null {
218221 const inputTypeName = node . name . value ;
219- if ( ! this . _usedNamedInputTypes [ inputTypeName ] ) {
220- return null ;
222+ if (
223+ ! this . _usedNamedInputTypes [ inputTypeName ] || // If not used...
224+ this . config . importSchemaTypesFrom // ... Or, is imported from a shared file
225+ ) {
226+ return null ; // ... then, don't generate in this file
221227 }
222228
229+ // Note: we usually don't need to export this type,
230+ // however, it's not possible to know if another file is using this type e.g. using `importSchemaTypesFrom`,
231+ // so it's better export the types.
232+
223233 if ( isOneOfInputObjectType ( this . _schema . getType ( inputTypeName ) ) ) {
224234 return new DeclarationBlock ( this . _declarationBlockConfig )
235+ . export ( )
225236 . asKind ( 'type' )
226237 . withName ( this . convertName ( node ) )
227238 . withComment ( node . description ?. value )
228239 . withContent ( `\n` + ( node . fields || [ ] ) . join ( '\n |' ) ) . string ;
229240 }
230241
231242 return new DeclarationBlock ( this . _declarationBlockConfig )
243+ . export ( )
232244 . asKind ( 'type' )
233245 . withName ( this . convertName ( node ) )
234246 . withComment ( node . description ?. value )
0 commit comments