Skip to content

Commit

Permalink
- use valid syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
laststylebender14 committed Sep 5, 2024
1 parent f2d6b94 commit ad57abd
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions src/core/config/transformer/rename_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Transform for RenameArgs {
let field_name = location.field_name.as_str();
let new_argument_name = location.new_argument_name.as_str();

let result = config
config
.types
.get_mut(type_name)
.and_then(|type_| type_.fields.get_mut(field_name))
Expand Down Expand Up @@ -107,41 +107,39 @@ impl Transform for RenameArgs {
))
}
},
);

if result.is_succeed() && config.is_root_operation_type(type_name) {
// We need to ensure we are doing the changes only if `existing_arg_name` is not query param type.
let is_safe_operation = config.types.get(type_name)
.and_then(|base_type| base_type.fields.get(field_name))
.map(|base_field| {
if let Some(Resolver::Http(http)) = &base_field.resolver {
!http.query.iter().any(|q| &q.key == existing_arg_name)
} else {
true
}
})
.unwrap_or(false);

if is_safe_operation {
config.types.values_mut().for_each(|type_| {
type_.fields.values_mut().for_each(|field_| {
if let Some(Resolver::Call(call)) = field_.resolver.as_mut() {
call.steps.iter_mut().for_each(|step| {
let new_f = field_name.to_owned();
let is_field_name_matched = step.query.as_ref().eq(&Some(&new_f))
|| step.mutation.as_ref().eq(&Some(&new_f));
if is_field_name_matched {
if let Some(arg) = step.args.remove(existing_arg_name) {
step.args.insert(new_argument_name.to_string(), arg);
}
}
})
).and_then(|_| {
if config.is_root_operation_type(type_name) {
let is_safe_operation = config.types.get(type_name)
.and_then(|base_type| base_type.fields.get(field_name))
.map(|base_field| {
if let Some(Resolver::Http(http)) = &base_field.resolver {
!http.query.iter().any(|q| &q.key == existing_arg_name)
} else {
true
}
})
});
}
}
result
.unwrap_or(false);
if is_safe_operation {
config.types.values_mut().for_each(|type_| {
type_.fields.values_mut().for_each(|field_| {
if let Some(Resolver::Call(call)) = field_.resolver.as_mut() {
call.steps.iter_mut().for_each(|step| {
let new_f = field_name.to_owned();
let is_field_name_matched = step.query.as_ref().eq(&Some(&new_f))
|| step.mutation.as_ref().eq(&Some(&new_f));
if is_field_name_matched {
if let Some(arg) = step.args.remove(existing_arg_name) {
step.args.insert(new_argument_name.to_string(), arg);
}
}
})
}
})
});
}
}
Valid::succeed(())
})
})
.map(|_| config)
}
Expand Down

0 comments on commit ad57abd

Please sign in to comment.