@@ -20,7 +20,6 @@ import {
20
20
Kind ,
21
21
GraphQLEnumType ,
22
22
} from 'graphql' ;
23
- import flatMap from 'array.prototype.flatmap' ;
24
23
import { BaseVisitor , ParsedConfig , RawConfig } from './base-visitor' ;
25
24
import { DEFAULT_SCALARS } from './scalars' ;
26
25
import { normalizeDeclarationKind } from './declaration-kinds' ;
@@ -329,7 +328,7 @@ export class BaseTypesVisitor<
329
328
}
330
329
331
330
NonNullType ( node : NonNullTypeNode ) : string {
332
- const asString = ( node . type as any ) as string ;
331
+ const asString = node . type as any as string ;
333
332
334
333
return asString ;
335
334
}
@@ -339,7 +338,7 @@ export class BaseTypesVisitor<
339
338
. export ( )
340
339
. asKind ( this . _parsedConfig . declarationKind . input )
341
340
. withName ( this . convertName ( node ) )
342
- . withComment ( ( node . description as any ) as string )
341
+ . withComment ( node . description as any as string )
343
342
. withBlock ( node . fields . join ( '\n' ) ) ;
344
343
}
345
344
@@ -348,7 +347,7 @@ export class BaseTypesVisitor<
348
347
}
349
348
350
349
InputValueDefinition ( node : InputValueDefinitionNode ) : string {
351
- const comment = transformComment ( ( node . description as any ) as string , 1 ) ;
350
+ const comment = transformComment ( node . description as any as string , 1 ) ;
352
351
const { input } = this . _parsedConfig . declarationKind ;
353
352
354
353
return comment + indent ( `${ node . name } : ${ node . type } ${ this . getPunctuation ( input ) } ` ) ;
@@ -359,7 +358,7 @@ export class BaseTypesVisitor<
359
358
}
360
359
361
360
FieldDefinition ( node : FieldDefinitionNode ) : string {
362
- const typeString = ( node . type as any ) as string ;
361
+ const typeString = node . type as any as string ;
363
362
const { type } = this . _parsedConfig . declarationKind ;
364
363
const comment = this . getFieldComment ( node ) ;
365
364
@@ -377,7 +376,7 @@ export class BaseTypesVisitor<
377
376
. export ( )
378
377
. asKind ( 'type' )
379
378
. withName ( this . convertName ( node ) )
380
- . withComment ( ( node . description as any ) as string )
379
+ . withComment ( node . description as any as string )
381
380
. withContent ( possibleTypes ) . string ;
382
381
}
383
382
@@ -414,7 +413,7 @@ export class BaseTypesVisitor<
414
413
. export ( )
415
414
. asKind ( type )
416
415
. withName ( this . convertName ( node ) )
417
- . withComment ( ( node . description as any ) as string ) ;
416
+ . withComment ( node . description as any as string ) ;
418
417
419
418
if ( type === 'interface' || type === 'class' ) {
420
419
if ( interfacesNames . length > 0 ) {
@@ -463,7 +462,7 @@ export class BaseTypesVisitor<
463
462
. export ( )
464
463
. asKind ( this . _parsedConfig . declarationKind . interface )
465
464
. withName ( this . convertName ( node ) )
466
- . withComment ( ( node . description as any ) as string ) ;
465
+ . withComment ( node . description as any as string ) ;
467
466
468
467
return declarationBlock . withBlock ( node . fields . join ( '\n' ) ) ;
469
468
}
@@ -509,28 +508,30 @@ export class BaseTypesVisitor<
509
508
}
510
509
511
510
public getEnumsImports ( ) : string [ ] {
512
- return flatMap ( Object . keys ( this . config . enumValues ) , enumName => {
513
- const mappedValue = this . config . enumValues [ enumName ] ;
514
-
515
- if ( mappedValue . sourceFile ) {
516
- if ( mappedValue . isDefault ) {
517
- return [ this . _buildTypeImport ( mappedValue . typeIdentifier , mappedValue . sourceFile , true ) ] ;
511
+ return Object . keys ( this . config . enumValues )
512
+ . flatMap ( enumName => {
513
+ const mappedValue = this . config . enumValues [ enumName ] ;
514
+
515
+ if ( mappedValue . sourceFile ) {
516
+ if ( mappedValue . isDefault ) {
517
+ return [ this . _buildTypeImport ( mappedValue . typeIdentifier , mappedValue . sourceFile , true ) ] ;
518
+ }
519
+
520
+ return this . handleEnumValueMapper (
521
+ mappedValue . typeIdentifier ,
522
+ mappedValue . importIdentifier ,
523
+ mappedValue . sourceIdentifier ,
524
+ mappedValue . sourceFile
525
+ ) ;
518
526
}
519
527
520
- return this . handleEnumValueMapper (
521
- mappedValue . typeIdentifier ,
522
- mappedValue . importIdentifier ,
523
- mappedValue . sourceIdentifier ,
524
- mappedValue . sourceFile
525
- ) ;
526
- }
527
-
528
- return [ ] ;
529
- } ) . filter ( a => a ) ;
528
+ return [ ] ;
529
+ } )
530
+ . filter ( Boolean ) ;
530
531
}
531
532
532
533
EnumTypeDefinition ( node : EnumTypeDefinitionNode ) : string {
533
- const enumName = ( node . name as any ) as string ;
534
+ const enumName = node . name as any as string ;
534
535
535
536
// In case of mapped external enum string
536
537
if ( this . config . enumValues [ enumName ] && this . config . enumValues [ enumName ] . sourceFile ) {
@@ -541,7 +542,7 @@ export class BaseTypesVisitor<
541
542
. export ( )
542
543
. asKind ( 'enum' )
543
544
. withName ( this . convertName ( node , { useTypesPrefix : this . config . enumPrefix } ) )
544
- . withComment ( ( node . description as any ) as string )
545
+ . withComment ( node . description as any as string )
545
546
. withBlock ( this . buildEnumValuesBlock ( enumName , node . values ) ) . string ;
546
547
}
547
548
@@ -567,7 +568,7 @@ export class BaseTypesVisitor<
567
568
const optionName = this . makeValidEnumIdentifier (
568
569
this . convertName ( enumOption , { useTypesPrefix : false , transformUnderscore : true } )
569
570
) ;
570
- const comment = transformComment ( ( enumOption . description as any ) as string , 1 ) ;
571
+ const comment = transformComment ( enumOption . description as any as string , 1 ) ;
571
572
const schemaEnumValue =
572
573
schemaEnumType && ! this . config . ignoreEnumValuesFromSchema
573
574
? schemaEnumType . getValue ( enumOption . name as any ) . value
@@ -644,7 +645,7 @@ export class BaseTypesVisitor<
644
645
}
645
646
646
647
protected _getTypeForNode ( node : NamedTypeNode ) : string {
647
- const typeAsString = ( node . name as any ) as string ;
648
+ const typeAsString = node . name as any as string ;
648
649
649
650
if ( this . scalars [ typeAsString ] ) {
650
651
return this . _getScalar ( typeAsString ) ;
@@ -674,7 +675,7 @@ export class BaseTypesVisitor<
674
675
}
675
676
676
677
ListType ( node : ListTypeNode ) : string {
677
- const asString = ( node . type as any ) as string ;
678
+ const asString = node . type as any as string ;
678
679
679
680
return this . wrapWithListType ( asString ) ;
680
681
}
0 commit comments