@@ -12,8 +12,7 @@ use crate::{
1212 } ,
1313 schema:: { Schema , TypeId } ,
1414 type_qualifiers:: GraphqlTypeQualifier ,
15- GraphQLClientCodegenOptions ,
16- GeneralError ,
15+ GeneralError , GraphQLClientCodegenOptions ,
1716} ;
1817use heck:: * ;
1918use proc_macro2:: { Ident , Span , TokenStream } ;
@@ -43,12 +42,27 @@ pub(crate) fn render_response_data_fields<'a>(
4342 if let Some ( custom_response_type) = options. custom_response_type ( ) {
4443 if operation. selection_set . len ( ) == 1 {
4544 let selection_id = operation. selection_set [ 0 ] ;
46- let selection_field = query. query . get_selection ( selection_id) . as_selected_field ( )
47- . ok_or_else ( || GeneralError ( format ! ( "Custom response type {custom_response_type} will only work on fields" ) ) ) ?;
48- calculate_custom_response_type_selection ( & mut expanded_selection, response_data_type_id, custom_response_type, selection_id, selection_field) ;
45+ let selection_field = query
46+ . query
47+ . get_selection ( selection_id)
48+ . as_selected_field ( )
49+ . ok_or_else ( || {
50+ GeneralError ( format ! (
51+ "Custom response type {custom_response_type} will only work on fields"
52+ ) )
53+ } ) ?;
54+ calculate_custom_response_type_selection (
55+ & mut expanded_selection,
56+ response_data_type_id,
57+ custom_response_type,
58+ selection_id,
59+ selection_field,
60+ ) ;
4961 return Ok ( expanded_selection) ;
5062 } else {
51- return Err ( GeneralError ( format ! ( "Custom response type {custom_response_type} requires single selection field" ) ) ) ;
63+ return Err ( GeneralError ( format ! (
64+ "Custom response type {custom_response_type} requires single selection field"
65+ ) ) ) ;
5266 }
5367 }
5468
@@ -66,10 +80,10 @@ pub(crate) fn render_response_data_fields<'a>(
6680fn calculate_custom_response_type_selection < ' a > (
6781 context : & mut ExpandedSelection < ' a > ,
6882 struct_id : ResponseTypeId ,
69- custom_response_type : & ' a String ,
83+ custom_response_type : & ' a str ,
7084 selection_id : SelectionId ,
71- field : & ' a SelectedField )
72- {
85+ field : & ' a SelectedField ,
86+ ) {
7387 let ( graphql_name, rust_name) = context. field_name ( field) ;
7488 let struct_name_string = full_path_prefix ( selection_id, context. query ) ;
7589 let field = context. query . schema . get_field ( field. field_id ) ;
@@ -88,7 +102,7 @@ fn calculate_custom_response_type_selection<'a>(
88102 name : struct_name_string. into ( ) ,
89103 } ) ;
90104 context. push_type_alias ( TypeAlias {
91- name : custom_response_type. as_str ( ) ,
105+ name : custom_response_type,
92106 struct_id,
93107 boxed : false ,
94108 } ) ;
0 commit comments