Skip to content

Commit

Permalink
keep the error path when redacting subgraph errors (#2273)
Browse files Browse the repository at this point in the history
Fix #1818 

the path is used to decide whether to assign the error on the primary or
deferred response
  • Loading branch information
Geal authored Dec 16, 2022
1 parent 4b6f62a commit 0c4a17f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
8 changes: 8 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ It defaults to 30 seconds.

By [@o0Ignition0o](https://github.com/o0Ignition0o) in https://github.com/apollographql/router/pull/2271

## 🐛 Fixes

### Keep the error path when redacting subgraph errors ([Issue #1818](https://github.com/apollographql/router/issues/1818))

Error redaction was erasing the error's path, which made it impossible to affect the errors to deferred responses. Now the redacted errors keep the path. Since the response shape for the primary and deferred responses are defined from the API schema, there is no possibility of leaking internal schema information here.

By [@Geal](https://github.com/geal) in https://github.com/apollographql/router/pull/2273

## 🛠 Maintenance

### Return more consistent errors ([Issue #2101](https://github.com/apollographql/router/issues/2101))
Expand Down
18 changes: 7 additions & 11 deletions apollo-router/src/plugins/include_subgraph_errors.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
use std::collections::HashMap;

use once_cell::sync::Lazy;
use schemars::JsonSchema;
use serde::Deserialize;
use tower::BoxError;
use tower::ServiceExt;

use crate::error::Error as SubgraphError;
use crate::json_ext::Object;
use crate::plugin::Plugin;
use crate::plugin::PluginInit;
use crate::register_plugin;
use crate::services::subgraph;
use crate::SubgraphResponse;

#[allow(clippy::field_reassign_with_default)]
static REDACTED_ERROR_MESSAGE: Lazy<Vec<SubgraphError>> = Lazy::new(|| {
let mut error: SubgraphError = Default::default();

error.message = "Subgraph errors redacted".to_string();

vec![error]
});
static REDACTED_ERROR_MESSAGE: &str = "Subgraph errors redacted";

register_plugin!("apollo", "include_subgraph_errors", IncludeSubgraphErrors);

Expand Down Expand Up @@ -57,7 +49,10 @@ impl Plugin for IncludeSubgraphErrors {
.map_response(move |mut response: SubgraphResponse| {
if !response.response.body().errors.is_empty() {
tracing::info!("redacted subgraph({sub_name_response}) errors");
response.response.body_mut().errors = REDACTED_ERROR_MESSAGE.clone();
for error in response.response.body_mut().errors.iter_mut() {
error.message = REDACTED_ERROR_MESSAGE.to_string();
error.extensions = Object::default();
}
}
response
})
Expand All @@ -82,6 +77,7 @@ mod test {
use std::sync::Arc;

use bytes::Bytes;
use once_cell::sync::Lazy;
use serde_json::Value as jValue;
use serde_json_bytes::ByteString;
use serde_json_bytes::Value;
Expand Down
4 changes: 0 additions & 4 deletions apollo-router/src/spec/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,10 +976,6 @@ impl Query {
response_path: Option<&Path>,
path: &Path,
) -> bool {
println!(
"Query::contains_error_path: path = {path}, query: {}",
self.string,
);
let operation = if let Some(subselection) = subselection {
// Get subselection from hashmap
match self.subselections.get(&SubSelection {
Expand Down

0 comments on commit 0c4a17f

Please sign in to comment.