Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2123 #2162

Merged
merged 2 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ From the CLI users can run:

There are situations where comments and whitespace are not preserved. This may be improved in future.

By [@bryncooke](https://github.com/bryncooke) in https://github.com/apollographql/router/pull/2116
By [@bryncooke](https://github.com/bryncooke) in https://github.com/apollographql/router/pull/2116, https://github.com/apollographql/router/pull/2162

### *Experimental* subgraph request retry ([Issue #338](https://github.com/apollographql/router/issues/338), [Issue #1956](https://github.com/apollographql/router/issues/1956))

Expand Down
54 changes: 42 additions & 12 deletions apollo-router/src/configuration/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,37 @@ fn apply_migration(config: &Value, migration: &Migration) -> Result<Value, Confi
for action in &migration.actions {
match action {
Action::Delete { path } => {
// Deleting isn't actually supported by protus so we add a magic value to delete later
transformer_builder = transformer_builder.add_action(
Parser::parse(REMOVAL_EXPRESSION, path).expect("migration must be valid"),
);
if !jsonpath_lib::select(config, path)
.unwrap_or_default()
.is_empty()
{
// Deleting isn't actually supported by protus so we add a magic value to delete later
transformer_builder = transformer_builder.add_action(
Parser::parse(REMOVAL_EXPRESSION, path).expect("migration must be valid"),
);
}
}
Action::Copy { from, to } => {
transformer_builder = transformer_builder
.add_action(Parser::parse(from, to).expect("migration must be valid"));
if !jsonpath_lib::select(config, from)
.unwrap_or_default()
.is_empty()
{
transformer_builder = transformer_builder
.add_action(Parser::parse(from, to).expect("migration must be valid"));
}
}
Action::Move { from, to } => {
transformer_builder = transformer_builder
.add_action(Parser::parse(from, to).expect("migration must be valid"));
// Deleting isn't actually supported by protus so we add a magic value to delete later
transformer_builder = transformer_builder.add_action(
Parser::parse(REMOVAL_EXPRESSION, from).expect("migration must be valid"),
);
if !jsonpath_lib::select(config, from)
.unwrap_or_default()
.is_empty()
{
transformer_builder = transformer_builder
.add_action(Parser::parse(from, to).expect("migration must be valid"));
// Deleting isn't actually supported by protus so we add a magic value to delete later
transformer_builder = transformer_builder.add_action(
Parser::parse(REMOVAL_EXPRESSION, from).expect("migration must be valid"),
);
}
}
}
}
Expand Down Expand Up @@ -258,6 +273,21 @@ mod test {
.expect("expected successful migration"));
}

#[test]
fn move_non_existent_field() {
insta::assert_json_snapshot!(apply_migration(
&json!({}),
&Migration::builder()
.action(Action::Move {
from: "obj.field1".to_string(),
to: "new.obj.field1".to_string()
})
.description("move field1")
.build(),
)
.expect("expected successful migration"));
}

#[test]
fn move_array_element() {
insta::assert_json_snapshot!(apply_migration(
Expand Down