@@ -23,6 +23,7 @@ export function buildDirectiveAnnotations(
2323 definitionNode : DefinitionNode ,
2424 config : CodegenConfigWithDefaults ,
2525 schema : GraphQLSchema ,
26+ annotationPrefix = "@" ,
2627) {
2728 const name = sanitizeName ( definitionNode . name . value ) ;
2829 const potentialMatchingInputType = schema . getType ( `${ name } Input` ) ;
@@ -36,7 +37,9 @@ export function buildDirectiveAnnotations(
3637 const directiveName = directive . name . value ;
3738 const federationReplacement =
3839 getFederationDirectiveReplacement ( directive ) ;
39- if ( federationReplacement ) return federationReplacement + "\n" ;
40+ if ( federationReplacement ) {
41+ return `${ applyAnnotationPrefix ( federationReplacement , annotationPrefix ) } \n` ;
42+ }
4043
4144 const directiveReplacementFromConfig = config . directiveReplacements ?. find (
4245 ( { directive, definitionType } ) => {
@@ -53,24 +56,32 @@ export function buildDirectiveAnnotations(
5356 ) ;
5457
5558 if ( directiveReplacementFromConfig ) {
56- return (
57- buildKotlinAnnotationsFromConfig (
58- directive ,
59- directiveReplacementFromConfig . kotlinAnnotations ,
60- ) . join ( "\n" ) + "\n"
59+ const annotations = buildKotlinAnnotationsFromConfig (
60+ directive ,
61+ directiveReplacementFromConfig . kotlinAnnotations ,
62+ annotationPrefix ,
6163 ) ;
64+ return annotations . join ( "\n" ) + "\n" ;
6265 }
6366 const customDirectiveFromConfig = config . customDirectives ?. find (
6467 ( directive ) => directive === directiveName ,
6568 ) ;
6669 if ( customDirectiveFromConfig ) {
67- return buildCustomDirective ( directive ) ;
70+ const customDirective = buildCustomDirective ( directive ) ;
71+ return applyAnnotationPrefix ( customDirective , annotationPrefix ) ;
6872 }
6973 return "" ;
7074 } )
7175 . join ( "" ) ;
7276}
7377
78+ function applyAnnotationPrefix ( annotation : string , prefix : string ) {
79+ const annotationWithoutAt = annotation . startsWith ( "@" )
80+ ? annotation . substring ( 1 )
81+ : annotation ;
82+ return `${ prefix } ${ annotationWithoutAt } ` ;
83+ }
84+
7485function buildCustomDirective ( directive : ConstDirectiveNode ) {
7586 const directiveName = directive . name . value ;
7687 return `@${ titleCase ( directiveName ) } \n` ;
@@ -81,9 +92,12 @@ function buildKotlinAnnotationsFromConfig(
8192 kotlinAnnotations : NonNullable <
8293 CodegenConfigWithDefaults [ "directiveReplacements" ]
8394 > [ number ] [ "kotlinAnnotations" ] ,
95+ annotationPrefix : string ,
8496) {
8597 return kotlinAnnotations . map ( ( kotlinAnnotation ) => {
86- if ( typeof kotlinAnnotation === "string" ) return kotlinAnnotation ;
98+ if ( typeof kotlinAnnotation === "string" ) {
99+ return applyAnnotationPrefix ( kotlinAnnotation , annotationPrefix ) ;
100+ }
87101 const directiveArguments = kotlinAnnotation . argumentsToRetain
88102 ?. map ( ( argumentToRetain ) => {
89103 const argumentValueNode = directive . arguments ?. find (
@@ -104,7 +118,7 @@ function buildKotlinAnnotationsFromConfig(
104118 return `${ argumentToRetain } = ${ argumentValue } ` ;
105119 } )
106120 . join ( ", " ) ;
107- return `@ ${ kotlinAnnotation . annotationName } (${ directiveArguments } )` ;
121+ return `${ annotationPrefix } ${ kotlinAnnotation . annotationName } (${ directiveArguments } )` ;
108122 } ) ;
109123}
110124
0 commit comments