Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: apollo-router/src/configuration/upgrade.rs
expression: "apply_migration(&json!({ \"should\" : \"stay\" }),\n &Migration::builder().action(Action::Move {\n from: \"obj.field1\".to_string(),\n to: \"new.obj.field1\".to_string(),\n }).description(\"move field1\").build()).expect(\"expected successful migration\")"
---
{
"should": "stay"
}
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, &format!("$.{}", 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, &format!("$.{}", 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, &format!("$.{}", 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!({"should": "stay"}),
&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