Skip to content
Merged
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
15 changes: 4 additions & 11 deletions apollo-federation/src/query_plan/fetch_dependency_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ impl FetchDependencyGraph {

/// Adds another node as a parent of `child`,
/// meaning that this fetch should happen after the provided one.
/// Assumption: The parent node is not a descendant of the child.
fn add_parent(&mut self, child_id: NodeIndex, parent_relation: ParentRelation) {
let ParentRelation {
parent_node_id,
Expand All @@ -738,8 +739,8 @@ impl FetchDependencyGraph {
return;
}
assert!(
!self.graph.contains_edge(child_id, parent_node_id),
"Node {parent_node_id:?} is a child of {child_id:?}: \
!self.is_descendant_of(parent_node_id, child_id),
"Node {parent_node_id:?} is a descendant of {child_id:?}: \
adding it as parent would create a cycle"
);
self.on_modification();
Expand Down Expand Up @@ -794,15 +795,7 @@ impl FetchDependencyGraph {
}

fn is_descendant_of(&self, node_id: NodeIndex, maybe_ancestor_id: NodeIndex) -> bool {
if node_id == maybe_ancestor_id {
return true;
}
for child_id in self.children_of(node_id) {
if self.is_descendant_of(child_id, maybe_ancestor_id) {
return true;
}
}
false
petgraph::algo::has_path_connecting(&self.graph, maybe_ancestor_id, node_id, None)
}

/// Returns whether `node_id` is both a child of `maybe_parent_id` but also if we can show that the
Expand Down