@@ -17,6 +17,7 @@ import { ConstDirectiveNode } from "graphql/language";
1717import { GraphQLSchema , isInputObjectType , Kind } from "graphql" ;
1818import { shouldConsolidateTypes } from "../utils/should-consolidate-types" ;
1919import { sanitizeName } from "../utils/sanitize-name" ;
20+ import { titleCase } from "../utils/title-case" ;
2021
2122export function buildDirectiveAnnotations (
2223 definitionNode : DefinitionNode ,
@@ -50,17 +51,32 @@ export function buildDirectiveAnnotations(
5051 return ! typeWillBeConsolidated ;
5152 } ,
5253 ) ;
53- if ( ! directiveReplacementFromConfig ) return "" ;
54- const kotlinAnnotations = buildKotlinAnnotations (
55- directive ,
56- directiveReplacementFromConfig . kotlinAnnotations ,
54+
55+ if ( directiveReplacementFromConfig ) {
56+ return (
57+ buildKotlinAnnotationsFromConfig (
58+ directive ,
59+ directiveReplacementFromConfig . kotlinAnnotations ,
60+ ) . join ( "\n" ) + "\n"
61+ ) ;
62+ }
63+ const customDirectiveFromConfig = config . customDirectives ?. find (
64+ ( directive ) => directive === directiveName ,
5765 ) ;
58- return kotlinAnnotations . join ( "\n" ) + "\n" ;
66+ if ( customDirectiveFromConfig ) {
67+ return buildCustomDirective ( directive ) ;
68+ }
69+ return "" ;
5970 } )
6071 . join ( "" ) ;
6172}
6273
63- function buildKotlinAnnotations (
74+ function buildCustomDirective ( directive : ConstDirectiveNode ) {
75+ const directiveName = directive . name . value ;
76+ return `@${ titleCase ( directiveName ) } \n` ;
77+ }
78+
79+ function buildKotlinAnnotationsFromConfig (
6480 directive : ConstDirectiveNode ,
6581 kotlinAnnotations : NonNullable <
6682 CodegenConfigWithDefaults [ "directiveReplacements" ]
0 commit comments