@@ -176,20 +176,19 @@ impl FetchStepSelections<MultiTypeFetchStep> {
176176 merge_selection_set ( selections, selection_set, false ) ;
177177 }
178178
179- pub fn safe_add_from_another_at_path (
179+ pub fn safe_migrate_from_another (
180180 & mut self ,
181181 other : & Self ,
182182 fetch_path : & MergePath ,
183183 ( self_used_for_requires, other_used_for_requires) : ( bool , bool ) ,
184184 ) -> Vec < ( String , AliasesRecords ) > {
185185 let mut aliases_made: Vec < ( String , AliasesRecords ) > = Vec :: new ( ) ;
186+ let maybe_merge_into = self . try_as_single ( ) . map ( |str| str. to_string ( ) ) ;
186187
187188 for ( definition_name, selection_set) in other. iter_selections ( ) {
188- // let target_type_name = self
189- // .get_definition_to_modify(fetch_path, definition_name)
190- // .to_string();
189+ let target_type = maybe_merge_into. as_ref ( ) . unwrap_or ( definition_name) ;
191190 let current = self
192- . selections_for_definition_mut ( & definition_name )
191+ . selections_for_definition_mut ( & target_type )
193192 . expect ( "missing" ) ;
194193
195194 if let Some ( selection_at_path) = find_selection_set_by_path_mut ( current, fetch_path) {
@@ -202,13 +201,13 @@ impl FetchStepSelections<MultiTypeFetchStep> {
202201 ) ;
203202
204203 if !current_aliases_made. is_empty ( ) {
205- aliases_made. push ( ( definition_name . to_string ( ) , current_aliases_made) ) ;
204+ aliases_made. push ( ( target_type . to_string ( ) , current_aliases_made) ) ;
206205 }
207206 } else {
208207 // TODO: Replace with error handling
209208 panic ! (
210209 "[{}]: Path '{}' cannot be found in selection set: '{}'" ,
211- definition_name , fetch_path, current
210+ target_type , fetch_path, current
212211 ) ;
213212 }
214213 }
0 commit comments