Skip to content

Commit

Permalink
chore(federation): address two TODOs in build_query_plan (#5876)
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop authored Aug 23, 2024
1 parent fbcda5b commit ae6ed86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 10 additions & 0 deletions apollo-federation/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Write;

use apollo_compiler::executable::GetOperationError;
use apollo_compiler::validation::DiagnosticList;
use apollo_compiler::validation::WithErrors;
use apollo_compiler::InvalidNameError;
Expand Down Expand Up @@ -56,6 +57,8 @@ pub enum SingleFederationError {
InvalidGraphQLName(#[from] InvalidNameError),
#[error("Subgraph invalid: {message}")]
InvalidSubgraph { message: String },
#[error("Operation name not found")]
UnknownOperation,
#[error("{message}")]
DirectiveDefinitionInvalid { message: String },
#[error("{message}")]
Expand Down Expand Up @@ -225,6 +228,7 @@ impl SingleFederationError {
SingleFederationError::InvalidGraphQL { .. }
| SingleFederationError::InvalidGraphQLName(_) => ErrorCode::InvalidGraphQL,
SingleFederationError::InvalidSubgraph { .. } => ErrorCode::InvalidGraphQL,
SingleFederationError::UnknownOperation => ErrorCode::InvalidGraphQL,
SingleFederationError::DirectiveDefinitionInvalid { .. } => {
ErrorCode::DirectiveDefinitionInvalid
}
Expand Down Expand Up @@ -406,6 +410,12 @@ impl From<InvalidNameError> for FederationError {
}
}

impl From<GetOperationError> for FederationError {
fn from(_: GetOperationError) -> Self {
SingleFederationError::UnknownOperation.into()
}
}

impl From<FederationSpecError> for FederationError {
fn from(err: FederationSpecError) -> Self {
// TODO: When we get around to finishing the composition port, we should really switch it to
Expand Down
10 changes: 4 additions & 6 deletions apollo-federation/src/query_plan/query_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,11 @@ impl QueryPlanner {
) -> Result<QueryPlan, FederationError> {
let operation = document
.operations
.get(operation_name.as_ref().map(|name| name.as_str()))
// TODO(@goto-bus-stop) this is not an internal error, but a user error
.map_err(|_| FederationError::internal("requested operation does not exist"))?;
.get(operation_name.as_ref().map(|name| name.as_str()))?;

if operation.selection_set.selections.is_empty() {
if operation.selection_set.is_empty() {
// This should never happen because `operation` comes from a known-valid document.
// TODO(@goto-bus-stop) it's probably fair to panic here :)
// We could panic here but we are returning a `Result` already anyways, so shrug!
return Err(FederationError::internal(
"Invalid operation: empty selection set",
));
Expand Down Expand Up @@ -413,7 +411,7 @@ impl QueryPlanner {
};
*/

if normalized_operation.selection_set.selections.is_empty() {
if normalized_operation.selection_set.is_empty() {
return Ok(QueryPlan::default());
}

Expand Down

0 comments on commit ae6ed86

Please sign in to comment.