@@ -13,11 +13,9 @@ import {
13
13
Kind ,
14
14
ListTypeNode ,
15
15
NamedTypeNode ,
16
- NameNode ,
17
16
NonNullTypeNode ,
18
17
ObjectTypeDefinitionNode ,
19
18
ScalarTypeDefinitionNode ,
20
- StringValueNode ,
21
19
UnionTypeDefinitionNode ,
22
20
} from 'graphql' ;
23
21
import { BaseVisitor , ParsedConfig , RawConfig } from './base-visitor.js' ;
@@ -658,7 +656,7 @@ export class BaseTypesVisitor<
658
656
. export ( )
659
657
. asKind ( this . _parsedConfig . declarationKind . input )
660
658
. withName ( this . convertName ( node ) )
661
- . withComment ( node . description as any as string )
659
+ . withComment ( node . description ?. value )
662
660
. withBlock ( node . fields . join ( '\n' ) ) ;
663
661
}
664
662
@@ -670,15 +668,14 @@ export class BaseTypesVisitor<
670
668
. export ( )
671
669
. asKind ( declarationKind )
672
670
. withName ( this . convertName ( node ) )
673
- . withComment ( node . description as any as string )
671
+ . withComment ( node . description ?. value )
674
672
. withContent ( `\n` + node . fields . join ( '\n |' ) ) ;
675
673
}
676
674
677
675
InputObjectTypeDefinition ( node : InputObjectTypeDefinitionNode ) : string {
678
676
if ( this . config . onlyEnums ) return '' ;
679
677
680
- // Why the heck is node.name a string and not { value: string } at runtime ?!
681
- if ( isOneOfInputObjectType ( this . _schema . getType ( node . name as unknown as string ) ) ) {
678
+ if ( isOneOfInputObjectType ( this . _schema . getType ( node . name . value ) ) ) {
682
679
return this . getInputObjectOneOfDeclarationBlock ( node ) . string ;
683
680
}
684
681
@@ -688,19 +685,15 @@ export class BaseTypesVisitor<
688
685
InputValueDefinition ( node : InputValueDefinitionNode ) : string {
689
686
if ( this . config . onlyEnums ) return '' ;
690
687
691
- const comment = transformComment ( node . description as any as string , 1 ) ;
688
+ const comment = transformComment ( node . description . value , 1 ) ;
692
689
const { input } = this . _parsedConfig . declarationKind ;
693
690
694
691
let type : string = node . type as any as string ;
695
692
if ( node . directives && this . config . directiveArgumentAndInputFieldMappings ) {
696
693
type = this . _getDirectiveOverrideType ( node . directives ) || type ;
697
694
}
698
695
699
- return comment + indent ( `${ node . name } : ${ type } ${ this . getPunctuation ( input ) } ` ) ;
700
- }
701
-
702
- Name ( node : NameNode ) : string {
703
- return node . value ;
696
+ return comment + indent ( `${ node . name . value } : ${ type } ${ this . getPunctuation ( input ) } ` ) ;
704
697
}
705
698
706
699
FieldDefinition ( node : FieldDefinitionNode ) : string {
@@ -710,7 +703,7 @@ export class BaseTypesVisitor<
710
703
const { type } = this . _parsedConfig . declarationKind ;
711
704
const comment = this . getNodeComment ( node ) ;
712
705
713
- return comment + indent ( `${ node . name } : ${ typeString } ${ this . getPunctuation ( type ) } ` ) ;
706
+ return comment + indent ( `${ node . name . value } : ${ typeString } ${ this . getPunctuation ( type ) } ` ) ;
714
707
}
715
708
716
709
UnionTypeDefinition ( node : UnionTypeDefinitionNode , key : string | number | undefined , parent : any ) : string {
@@ -724,7 +717,7 @@ export class BaseTypesVisitor<
724
717
. export ( )
725
718
. asKind ( 'type' )
726
719
. withName ( this . convertName ( node ) )
727
- . withComment ( node . description as any as string )
720
+ . withComment ( node . description . value )
728
721
. withContent ( possibleTypes ) . string ;
729
722
}
730
723
@@ -747,9 +740,9 @@ export class BaseTypesVisitor<
747
740
...( this . config . addTypename
748
741
? [
749
742
indent (
750
- `${ this . config . immutableTypes ? 'readonly ' : '' } ${ optionalTypename } : '${ node . name } ' ${ this . getPunctuation (
751
- type
752
- ) } `
743
+ `${ this . config . immutableTypes ? 'readonly ' : '' } ${ optionalTypename } : '${
744
+ node . name . value
745
+ } ' ${ this . getPunctuation ( type ) } `
753
746
) ,
754
747
]
755
748
: [ ] ) ,
@@ -761,7 +754,7 @@ export class BaseTypesVisitor<
761
754
. export ( )
762
755
. asKind ( type )
763
756
. withName ( this . convertName ( node ) )
764
- . withComment ( node . description as any as string ) ;
757
+ . withComment ( node . description ?. value ) ;
765
758
766
759
if ( type === 'interface' || type === 'class' ) {
767
760
if ( interfacesNames . length > 0 ) {
@@ -799,7 +792,7 @@ export class BaseTypesVisitor<
799
792
. export ( )
800
793
. asKind ( this . _parsedConfig . declarationKind . interface )
801
794
. withName ( this . convertName ( node ) )
802
- . withComment ( node . description as any as string ) ;
795
+ . withComment ( node . description ?. value ) ;
803
796
804
797
return declarationBlock . withBlock ( node . fields . join ( '\n' ) ) ;
805
798
}
@@ -873,7 +866,7 @@ export class BaseTypesVisitor<
873
866
}
874
867
875
868
EnumTypeDefinition ( node : EnumTypeDefinitionNode ) : string {
876
- const enumName = node . name as any as string ;
869
+ const enumName = node . name . value ;
877
870
878
871
// In case of mapped external enum string
879
872
if ( this . config . enumValues [ enumName ] ?. sourceFile ) {
@@ -889,15 +882,10 @@ export class BaseTypesVisitor<
889
882
useTypesSuffix : this . config . enumSuffix ,
890
883
} )
891
884
)
892
- . withComment ( node . description as any as string )
885
+ . withComment ( node . description . value )
893
886
. withBlock ( this . buildEnumValuesBlock ( enumName , node . values ) ) . string ;
894
887
}
895
888
896
- // We are using it in order to transform "description" field
897
- StringValue ( node : StringValueNode ) : string {
898
- return node . value ;
899
- }
900
-
901
889
protected makeValidEnumIdentifier ( identifier : string ) : string {
902
890
if ( / ^ [ 0 - 9 ] / . exec ( identifier ) ) {
903
891
return wrapWithSingleQuotes ( identifier , true ) ;
@@ -921,10 +909,10 @@ export class BaseTypesVisitor<
921
909
const comment = this . getNodeComment ( enumOption ) ;
922
910
const schemaEnumValue =
923
911
schemaEnumType && ! this . config . ignoreEnumValuesFromSchema
924
- ? schemaEnumType . getValue ( enumOption . name as any ) . value
912
+ ? schemaEnumType . getValue ( enumOption . name . value ) . value
925
913
: undefined ;
926
914
let enumValue : string | number =
927
- typeof schemaEnumValue === 'undefined' ? ( enumOption . name as any ) : schemaEnumValue ;
915
+ typeof schemaEnumValue === 'undefined' ? enumOption . name . value : schemaEnumValue ;
928
916
929
917
if ( typeof this . config . enumValues [ typeName ] ?. mappedValues ?. [ enumValue ] !== 'undefined' ) {
930
918
enumValue = this . config . enumValues [ typeName ] . mappedValues [ enumValue ] ;
@@ -956,7 +944,7 @@ export class BaseTypesVisitor<
956
944
. export ( )
957
945
. asKind ( this . _parsedConfig . declarationKind . arguments )
958
946
. withName ( this . convertName ( name ) )
959
- . withComment ( node . description )
947
+ . withComment ( node . description ?. value )
960
948
. withBlock ( this . _argumentsTransformer . transform < InputValueDefinitionNode > ( field . arguments ) ) ;
961
949
}
962
950
@@ -998,7 +986,7 @@ export class BaseTypesVisitor<
998
986
protected _getDirectiveOverrideType ( directives : ReadonlyArray < DirectiveNode > ) : string | null {
999
987
const type = directives
1000
988
. map ( directive => {
1001
- const directiveName = directive . name as any as string ;
989
+ const directiveName = directive . name . value ;
1002
990
if ( this . config . directiveArgumentAndInputFieldMappings [ directiveName ] ) {
1003
991
return this . _getDirectiveArgumentNadInputFieldMapping ( directiveName ) ;
1004
992
}
@@ -1011,7 +999,7 @@ export class BaseTypesVisitor<
1011
999
}
1012
1000
1013
1001
protected _getTypeForNode ( node : NamedTypeNode , isVisitingInputType : boolean ) : string {
1014
- const typeAsString = node . name as any as string ;
1002
+ const typeAsString = node . name . value ;
1015
1003
1016
1004
if ( this . scalars [ typeAsString ] ) {
1017
1005
return this . _getScalar ( typeAsString , isVisitingInputType ? 'input' : 'output' ) ;
@@ -1020,7 +1008,7 @@ export class BaseTypesVisitor<
1020
1008
return this . config . enumValues [ typeAsString ] . typeIdentifier ;
1021
1009
}
1022
1010
1023
- const schemaType = this . _schema . getType ( node . name as any ) ;
1011
+ const schemaType = this . _schema . getType ( typeAsString ) ;
1024
1012
1025
1013
if ( schemaType && isEnumType ( schemaType ) ) {
1026
1014
return this . convertName ( node , {
@@ -1055,8 +1043,8 @@ export class BaseTypesVisitor<
1055
1043
}
1056
1044
1057
1045
getNodeComment ( node : FieldDefinitionNode | EnumValueDefinitionNode | InputValueDefinitionNode ) : string {
1058
- let commentText : string = node . description as any ;
1059
- const deprecationDirective = node . directives . find ( ( v : any ) => v . name === 'deprecated' ) ;
1046
+ let commentText = node . description ?. value ;
1047
+ const deprecationDirective = node . directives . find ( v => v . name . value === 'deprecated' ) ;
1060
1048
if ( deprecationDirective ) {
1061
1049
const deprecationReason = this . getDeprecationReason ( deprecationDirective ) ;
1062
1050
commentText = `${ commentText ? `${ commentText } \n` : '' } @deprecated ${ deprecationReason } ` ;
@@ -1066,11 +1054,11 @@ export class BaseTypesVisitor<
1066
1054
}
1067
1055
1068
1056
protected getDeprecationReason ( directive : DirectiveNode ) : string | void {
1069
- if ( ( directive . name as any ) === 'deprecated' ) {
1070
- const hasArguments = directive . arguments . length > 0 ;
1057
+ if ( directive . name . value === 'deprecated' ) {
1071
1058
let reason = 'Field no longer supported' ;
1072
- if ( hasArguments ) {
1073
- reason = directive . arguments [ 0 ] . value as any ;
1059
+ const deprecatedReason = directive . arguments [ 0 ] ;
1060
+ if ( deprecatedReason && deprecatedReason . value . kind === Kind . STRING ) {
1061
+ reason = deprecatedReason . value . value ;
1074
1062
}
1075
1063
return reason ;
1076
1064
}
0 commit comments