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
5 changes: 5 additions & 0 deletions .changesets/feat_glasser_pq_error_include_extensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### pq: include operation name in `PERSISTED_QUERY_NOT_IN_LIST` error ([PR #7768](https://github.com/apollographql/router/pull/7768))

When persisted query safelisting is enabled and a request has an unknown PQ ID, the GraphQL error now has the extension field `operation_name` containing the GraphQL operation name (if provided explicitly in the request).

By [@glasser](https://github.com/glasser) in https://github.com/apollographql/router/pull/7768
31 changes: 23 additions & 8 deletions apollo-router/src/services/layers/persisted_queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,19 +371,30 @@ impl ErrorCacheStrategy {
}
}

fn graphql_err_operation_not_found(persisted_query_id: &str) -> GraphQLError {
graphql_err(
"PERSISTED_QUERY_NOT_IN_LIST",
&format!("Persisted query '{persisted_query_id}' not found in the persisted query list"),
)
fn graphql_err_operation_not_found(
persisted_query_id: &str,
operation_name: Option<String>,
) -> GraphQLError {
let mut builder = GraphQLError::builder()
.extension_code("PERSISTED_QUERY_NOT_IN_LIST")
.message(format!(
"Persisted query '{persisted_query_id}' not found in the persisted query list"
));
if let Some(operation_name) = operation_name {
builder = builder.extension("operation_name", operation_name);
}
builder.build()
}

fn supergraph_err_operation_not_found(
request: SupergraphRequest,
persisted_query_id: &str,
) -> SupergraphResponse {
supergraph_err(
graphql_err_operation_not_found(persisted_query_id),
graphql_err_operation_not_found(
persisted_query_id,
request.supergraph_request.body().operation_name.clone(),
),
request,
ErrorCacheStrategy::DontCache,
StatusCode::NOT_FOUND,
Expand Down Expand Up @@ -705,7 +716,7 @@ mod tests {
.expect("could not get response from pq layer");
assert_eq!(
response.errors,
vec![graphql_err_operation_not_found(invalid_id)]
vec![graphql_err_operation_not_found(invalid_id, None)]
);
}

Expand Down Expand Up @@ -1067,6 +1078,7 @@ mod tests {
"persistedQuery",
json!({"version": 1, "sha256Hash": invalid_id}),
)
.operation_name("SomeOperation")
.build()
.unwrap();

Expand All @@ -1080,7 +1092,10 @@ mod tests {
.expect("could not get response from pq layer");
assert_eq!(
response.errors,
vec![graphql_err_operation_not_found(invalid_id)]
vec![graphql_err_operation_not_found(
invalid_id,
Some("SomeOperation".to_string()),
)]
);
}

Expand Down