Skip to content

Commit

Permalink
FED-38: [operation processing] re-add __typename to selection sets wi…
Browse files Browse the repository at this point in the history
…th sibling_typename (#5082)

Co-authored-by: Renée <renee.kooi@apollographql.com>
  • Loading branch information
duckki and goto-bus-stop committed May 8, 2024
1 parent 1b34313 commit f414230
Show file tree
Hide file tree
Showing 4 changed files with 443 additions and 34 deletions.
37 changes: 15 additions & 22 deletions apollo-federation/src/query_graph/graph_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ use crate::query_graph::QueryGraphEdgeTransition;
use crate::query_graph::QueryGraphNodeType;
use crate::query_plan::operation::Field;
use crate::query_plan::operation::FieldData;
use crate::query_plan::operation::FieldSelection;
use crate::query_plan::operation::InlineFragment;
use crate::query_plan::operation::InlineFragmentData;
use crate::query_plan::operation::InlineFragmentSelection;
use crate::query_plan::operation::Selection;
use crate::query_plan::operation::RebaseErrorHandlingOption;
use crate::query_plan::operation::SelectionId;
use crate::query_plan::operation::SelectionSet;
use crate::query_plan::FetchDataPathElement;
Expand Down Expand Up @@ -407,27 +405,22 @@ impl OpPathElement {
}
}
}
}

pub(crate) fn selection_of_element(
element: OpPathElement,
sub_selection: Option<SelectionSet>,
) -> Result<Selection, FederationError> {
// TODO: validate that the subSelection is ok for the element
Ok(match element {
OpPathElement::Field(field) => Selection::Field(Arc::new(FieldSelection {
field,
selection_set: sub_selection,
})),
OpPathElement::InlineFragment(inline_fragment) => {
Selection::InlineFragment(Arc::new(InlineFragmentSelection {
inline_fragment,
selection_set: sub_selection.ok_or_else(|| {
FederationError::internal("Expected a selection set for an inline fragment")
})?,
}))
pub(crate) fn rebase_on(
&self,
parent_type: &CompositeTypeDefinitionPosition,
schema: &ValidFederationSchema,
error_handling: RebaseErrorHandlingOption,
) -> Result<Option<OpPathElement>, FederationError> {
match self {
OpPathElement::Field(field) => field
.rebase_on(parent_type, schema, error_handling)
.map(|val| val.map(Into::into)),
OpPathElement::InlineFragment(inline) => inline
.rebase_on(parent_type, schema, error_handling)
.map(|val| val.map(Into::into)),
}
})
}
}

impl Display for OpPathElement {
Expand Down
6 changes: 3 additions & 3 deletions apollo-federation/src/query_plan/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use indexmap::map::Entry;
use indexmap::IndexMap;

use crate::error::FederationError;
use crate::query_graph::graph_path::selection_of_element;
use crate::query_graph::graph_path::OpPathElement;
use crate::query_plan::operation::Selection;
use crate::query_plan::operation::SelectionMap;
use crate::query_plan::operation::SelectionSet;

Expand Down Expand Up @@ -221,12 +221,12 @@ pub(crate) fn remove_conditions_from_selection_set(
selection.with_updated_selection_set(Some(updated_selection_set))?
}
} else {
selection_of_element(updated_element, Some(updated_selection_set))?
Selection::from_element(updated_element, Some(updated_selection_set))?
}
} else if updated_element == element {
selection.clone()
} else {
selection_of_element(updated_element, None)?
Selection::from_element(updated_element, None)?
};
selection_map.insert(new_selection);
}
Expand Down
3 changes: 1 addition & 2 deletions apollo-federation/src/query_plan/fetch_dependency_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use petgraph::visit::EdgeRef;
use crate::error::FederationError;
use crate::error::SingleFederationError;
use crate::link::graphql_definition::DeferDirectiveArguments;
use crate::query_graph::graph_path::selection_of_element;
use crate::query_graph::graph_path::OpGraphPathContext;
use crate::query_graph::graph_path::OpGraphPathTrigger;
use crate::query_graph::graph_path::OpPath;
Expand Down Expand Up @@ -1473,7 +1472,7 @@ fn operation_for_entities_fetch(

let entities = FieldDefinitionPosition::Object(query_type.field(ENTITIES_QUERY.clone()));

let entities_call = selection_of_element(
let entities_call = Selection::from_element(
OpPathElement::Field(Field::new(FieldData {
schema: subgraph_schema.clone(),
field_position: entities,
Expand Down
Loading

0 comments on commit f414230

Please sign in to comment.