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
9 changes: 9 additions & 0 deletions .changesets/fix_caroline_rh_1292.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Handle both 'deprecated' enum values when merging coprocessor context ([PR #8913](https://github.com/apollographql/router/pull/8913))

A change to coprocessor context merges in Router v2.10 caused keys to be deleted when `context: true` is used as the coprocessor context selector in the router configuration file.

The quick fix in the router config is to pass `context: deprecated` instead.

This change brings parity when `context: true` is provided.

By [@carodewig](https://github.com/carodewig) in https://github.com/apollographql/router/pull/8913
11 changes: 10 additions & 1 deletion apollo-router/src/plugins/coprocessor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,15 @@ pub(super) enum ContextConf {
NewContextConf(NewContextConf),
}

impl ContextConf {
fn is_deprecated(&self) -> bool {
match self {
Self::Deprecated(v) => *v,
Self::NewContextConf(c) => *c == NewContextConf::Deprecated,
}
}
}

impl Default for ContextConf {
fn default() -> Self {
Self::Deprecated(false)
Expand Down Expand Up @@ -564,7 +573,7 @@ pub(crate) fn update_context_from_coprocessor(

for (mut key, value) in context_returned.try_into_iter()? {
// Handle deprecated key names - convert back to actual key names
if let ContextConf::NewContextConf(NewContextConf::Deprecated) = context_config {
if context_config.is_deprecated() {
key = context_key_from_deprecated(key);
}

Expand Down
32 changes: 32 additions & 0 deletions apollo-router/src/plugins/coprocessor/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mod tests {

use super::super::*;
use crate::assert_response_eq_ignoring_error_id;
use crate::context::deprecated::DEPRECATED_CLIENT_NAME;
use crate::graphql::Response;
use crate::json_ext::Object;
use crate::json_ext::Value;
Expand All @@ -92,6 +93,7 @@ mod tests {
use crate::plugins::coprocessor::supergraph::SupergraphStage;
use crate::plugins::coprocessor::test::assert_coprocessor_operations_metrics;
use crate::plugins::coprocessor::was_incoming_payload_valid;
use crate::plugins::telemetry::CLIENT_NAME;
use crate::plugins::telemetry::config_new::conditions::SelectorOrValue;
use crate::services::external::EXTERNALIZABLE_VERSION;
use crate::services::external::Externalizable;
Expand Down Expand Up @@ -4316,6 +4318,36 @@ mod tests {
);
}

#[rstest::rstest]
fn test_update_context_from_coprocessor_handles_deprecated_key_names(
#[values(DEPRECATED_CLIENT_NAME, CLIENT_NAME)] target_context_key_name: &str,
#[values(
ContextConf::Deprecated(true),
ContextConf::NewContextConf(NewContextConf::Deprecated)
)]
context_conf: ContextConf,
) {
use crate::Context;
use crate::plugins::coprocessor::update_context_from_coprocessor;

let target_context =
Context::from_iter([(target_context_key_name.to_string(), "v1".into())]);
let returned_context =
Context::from_iter([(DEPRECATED_CLIENT_NAME.to_string(), "v2".into())]);

update_context_from_coprocessor(&target_context, returned_context, &context_conf).unwrap();

assert_eq!(
target_context.get_json_value(CLIENT_NAME),
Some(json!("v2")),
);

assert!(
!target_context.contains_key(DEPRECATED_CLIENT_NAME),
"DEPRECATED_CLIENT_NAME should not be present"
);
}

// Subgraph stage metrics test
#[tokio::test]
async fn subgraph_request_metric_incremented_when_condition_true() {
Expand Down