@@ -9,6 +9,18 @@ use heck::{ToSnakeCase, ToUpperCamelCase};
99use proc_macro2:: { Ident , Span , TokenStream } ;
1010use quote:: { quote, ToTokens } ;
1111
12+ fn to_snake_case_preserve_trailing_underscores ( s : & str ) -> String {
13+ let trailing_underscores = s. chars ( ) . rev ( ) . take_while ( |& c| c == '_' ) . count ( ) ;
14+ if trailing_underscores == 0 {
15+ s. to_snake_case ( )
16+ } else {
17+ let without_trailing = & s[ ..s. len ( ) - trailing_underscores] ;
18+ let suffix = "_" . repeat ( trailing_underscores) ;
19+ format ! ( "{}{}" , without_trailing. to_snake_case( ) , suffix)
20+ }
21+ }
22+
23+
1224pub ( super ) fn generate_input_object_definitions (
1325 all_used_types : & UsedTypes ,
1426 options : & GraphQLClientCodegenOptions ,
@@ -61,7 +73,7 @@ fn generate_struct(
6173 let struct_name = Ident :: new ( safe_name. as_ref ( ) , Span :: call_site ( ) ) ;
6274
6375 let fields = input. fields . iter ( ) . map ( |( field_name, field_type) | {
64- let safe_field_name = keyword_replace ( field_name . to_snake_case ( ) ) ;
76+ let safe_field_name = keyword_replace ( to_snake_case_preserve_trailing_underscores ( field_name ) ) ;
6577 let annotation = field_rename_annotation ( field_name, safe_field_name. as_ref ( ) ) ;
6678 let name_ident = Ident :: new ( safe_field_name. as_ref ( ) , Span :: call_site ( ) ) ;
6779 let normalized_field_type_name = options
0 commit comments