@@ -83,8 +83,12 @@ fn to_pascal_case(s: &str) -> String {
8383
8484fn apply_naming_convention ( s : & str , naming_convention : & str ) -> String {
8585 match naming_convention {
86+ "change-case-all#pascalCase" => to_pascal_case ( s) ,
8687 "change-case-all#upperCaseFirst" => upper_case_first ( s) ,
87- _ => to_pascal_case ( s) ,
88+ // GraphQL Codegen supports `keep`; preserve casing in that mode.
89+ "keep" => s. to_string ( ) ,
90+ // Keep unknown/custom conventions unchanged instead of forcing PascalCase.
91+ _ => s. to_string ( ) ,
8892 }
8993}
9094
@@ -340,6 +344,30 @@ fn naming_convention_default() -> String {
340344 "change-case-all#pascalCase" . to_string ( )
341345}
342346
347+ #[ derive( Deserialize ) ]
348+ #[ serde( untagged) ]
349+ enum NamingConventionOption {
350+ String ( String ) ,
351+ Object ( serde_json:: Value ) ,
352+ }
353+
354+ impl NamingConventionOption {
355+ fn as_type_name_convention ( & self ) -> String {
356+ match self {
357+ NamingConventionOption :: String ( v) => v. to_string ( ) ,
358+ NamingConventionOption :: Object ( v) => v
359+ . get ( "typeNames" )
360+ . and_then ( |t| t. as_str ( ) )
361+ . map ( str:: to_string)
362+ . unwrap_or_else ( naming_convention_default) ,
363+ }
364+ }
365+ }
366+
367+ fn naming_convention_option_default ( ) -> NamingConventionOption {
368+ NamingConventionOption :: String ( naming_convention_default ( ) )
369+ }
370+
343371#[ allow( non_snake_case) ]
344372#[ derive( Deserialize ) ]
345373struct PluginOptions {
@@ -348,8 +376,8 @@ struct PluginOptions {
348376 #[ serde( default = "gql_default" ) ]
349377 gqlTagName : String ,
350378
351- #[ serde( default = "naming_convention_default " ) ]
352- namingConvention : String ,
379+ #[ serde( default = "naming_convention_option_default " ) ]
380+ namingConvention : NamingConventionOption ,
353381}
354382
355383#[ plugin_transform]
@@ -380,7 +408,7 @@ pub fn process_transform(program: Program, metadata: TransformPluginProgramMetad
380408 cwd,
381409 artifact_directory,
382410 gql_tag_name : plugin_config. gqlTagName ,
383- naming_convention : plugin_config. namingConvention ,
411+ naming_convention : plugin_config. namingConvention . as_type_name_convention ( ) ,
384412 } ) ;
385413
386414 program. apply ( & mut visit_mut_pass ( visitor) )
0 commit comments