Skip to content

Commit 5781ca7

Browse files
committed
fix: clippy collapsible-if and rustfmt formatting
1 parent 33bca55 commit 5781ca7

File tree

5 files changed

+52
-55
lines changed

5 files changed

+52
-55
lines changed

apollo-federation/src/connectors/expand/mod.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,15 @@ fn add_connected_selections(
247247
use apollo_compiler::ast::InputValueDefinition;
248248
use apollo_compiler::ast::Type;
249249
let join_field_def = join_field_def.make_mut();
250-
join_field_def.arguments.push(Node::new(InputValueDefinition {
251-
description: None,
252-
name: JOIN_CONNECTED_SELECTION_ARGUMENT_NAME,
253-
ty: Node::new(Type::Named(name!("join__FieldSet"))),
254-
default_value: None,
255-
directives: Default::default(),
256-
}));
250+
join_field_def
251+
.arguments
252+
.push(Node::new(InputValueDefinition {
253+
description: None,
254+
name: JOIN_CONNECTED_SELECTION_ARGUMENT_NAME,
255+
ty: Node::new(Type::Named(name!("join__FieldSet"))),
256+
default_value: None,
257+
directives: Default::default(),
258+
}));
257259
}
258260
}
259261

@@ -306,10 +308,10 @@ fn build_service_name_to_enum_value(
306308
// Look for @join__graph(name: "service_name") on this enum value
307309
for directive in enum_value_def.directives.get_all(&name!("join__graph")) {
308310
for arg in &directive.arguments {
309-
if arg.name == name!("name") {
310-
if let Value::String(service_name) = arg.value.as_ref() {
311-
map.insert(service_name.clone(), enum_value_name.clone());
312-
}
311+
if arg.name == name!("name")
312+
&& let Value::String(service_name) = arg.value.as_ref()
313+
{
314+
map.insert(service_name.clone(), enum_value_name.clone());
313315
}
314316
}
315317
}

apollo-federation/src/connectors/validation/connect/selection.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,7 @@ impl<'schema> Selection<'schema> {
176176
return Ok(Vec::new());
177177
}
178178

179-
let mut validator = SelectionValidator::new(
180-
schema,
181-
&self.node,
182-
self.coordinate,
183-
);
179+
let mut validator = SelectionValidator::new(schema, &self.node, self.coordinate);
184180

185181
// Clear seen_fields for this connector
186182
validator.seen_fields.clear();
@@ -216,11 +212,7 @@ impl<'schema> Selection<'schema> {
216212
});
217213
}
218214

219-
let mut validator = SelectionValidator::new(
220-
schema,
221-
&self.node,
222-
self.coordinate,
223-
);
215+
let mut validator = SelectionValidator::new(schema, &self.node, self.coordinate);
224216

225217
// Clear seen_fields for this connector
226218
validator.seen_fields.clear();

apollo-federation/src/query_graph/build_query_graph.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use crate::bail;
1818
use crate::error::FederationError;
1919
use crate::error::SingleFederationError;
2020
use crate::link::federation_spec_definition::FederationSpecDefinition;
21-
use crate::link::join_spec_definition::JoinSpecDefinition;
2221
use crate::link::federation_spec_definition::KeyDirectiveArguments;
2322
use crate::link::federation_spec_definition::get_federation_spec_definition_from_subgraph;
23+
use crate::link::join_spec_definition::JoinSpecDefinition;
2424
use crate::operation::Selection;
2525
use crate::operation::SelectionSet;
2626
use crate::operation::merge_selection_sets;
@@ -2210,10 +2210,8 @@ impl FederatedQueryGraphBuilder {
22102210
/// nodes that only have the specified field edges plus key resolution edges.
22112211
fn handle_connected_selection(&mut self) -> Result<(), FederationError> {
22122212
// Get join spec from supergraph
2213-
let (_, join_spec, _) =
2214-
validate_supergraph_for_query_planning(&self.supergraph_schema)?;
2215-
let join_field_def =
2216-
join_spec.field_directive_definition(&self.supergraph_schema)?;
2213+
let (_, join_spec, _) = validate_supergraph_for_query_planning(&self.supergraph_schema)?;
2214+
let join_field_def = join_spec.field_directive_definition(&self.supergraph_schema)?;
22172215
let join_field_name = join_field_def.name.clone();
22182216

22192217
// Build graph enum value -> source name mapping
@@ -2244,13 +2242,12 @@ impl FederatedQueryGraphBuilder {
22442242
let args = join_spec.field_directive_arguments(directive)?;
22452243
if let (Some(graph_enum_value), Some(connected_sel)) =
22462244
(args.graph, args.connected_selection)
2245+
&& let Some(source_name) = graph_enum_to_source.get(&graph_enum_value)
22472246
{
2248-
if let Some(source_name) = graph_enum_to_source.get(&graph_enum_value) {
2249-
restrictions.insert(
2250-
(source_name.clone(), type_name.clone(), field_name.clone()),
2251-
connected_sel.to_string(),
2252-
);
2253-
}
2247+
restrictions.insert(
2248+
(source_name.clone(), type_name.clone(), field_name.clone()),
2249+
connected_sel.to_string(),
2250+
);
22542251
}
22552252
}
22562253
}
@@ -2300,8 +2297,7 @@ impl FederatedQueryGraphBuilder {
23002297
let conditions = parse_field_set(schema, tail_type_name, connected_sel, true)?;
23012298

23022299
provide_id += 1;
2303-
let new_tail =
2304-
self.create_restricted_copy(tail, &source, &conditions, provide_id)?;
2300+
let new_tail = self.create_restricted_copy(tail, &source, &conditions, provide_id)?;
23052301
Self::update_edge_tail(&mut self.base, edge, new_tail)?;
23062302
// Mark ancestors of the head as having reachable "cross-subgraph"
23072303
// edges. Even though the restricted copy is in the same subgraph,
@@ -2318,8 +2314,7 @@ impl FederatedQueryGraphBuilder {
23182314
&self,
23192315
join_spec: &'static JoinSpecDefinition,
23202316
) -> Result<IndexMap<Name, Arc<str>>, FederationError> {
2321-
let graph_directive_def =
2322-
join_spec.graph_directive_definition(&self.supergraph_schema)?;
2317+
let graph_directive_def = join_spec.graph_directive_definition(&self.supergraph_schema)?;
23232318
let graph_enum_name = self
23242319
.supergraph_schema
23252320
.schema()
@@ -2410,10 +2405,10 @@ impl FederatedQueryGraphBuilder {
24102405
// Register in types_to_nodes for the federated graph
24112406
let current_source = self.base.query_graph.current_source.clone();
24122407
self.base.query_graph.current_source = FEDERATED_GRAPH_ROOT_SOURCE.into();
2413-
if let Ok(nodes) = self.base.query_graph.types_to_nodes_mut() {
2414-
if let Some(node_set) = nodes.get_mut(type_pos.type_name()) {
2415-
node_set.insert(new_node);
2416-
}
2408+
if let Ok(nodes) = self.base.query_graph.types_to_nodes_mut()
2409+
&& let Some(node_set) = nodes.get_mut(type_pos.type_name())
2410+
{
2411+
node_set.insert(new_node);
24172412
}
24182413
self.base.query_graph.current_source = current_source;
24192414

@@ -2459,12 +2454,8 @@ impl FederatedQueryGraphBuilder {
24592454
if let Some((transition, tail)) = existing {
24602455
if let Some(nested_selections) = &field_selection.selection_set {
24612456
// Nested selection - create another restricted copy for the next level
2462-
let new_tail = self.create_restricted_copy(
2463-
tail,
2464-
source,
2465-
nested_selections,
2466-
provide_id,
2467-
)?;
2457+
let new_tail =
2458+
self.create_restricted_copy(tail, source, nested_selections, provide_id)?;
24682459
self.base
24692460
.add_edge(restricted_node, new_tail, transition, None, None)?;
24702461
} else {

apollo-federation/src/query_graph/graph_path.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,8 +1725,9 @@ where
17251725
// node. Copy nodes have fewer fields than the original, so the
17261726
// "detour" (re-entering the subgraph) is actually necessary to
17271727
// access fields not on the copy.
1728-
if !tail_is_copy && let Some(last_subgraph_entering_edge_info) =
1729-
&to_advance.last_subgraph_entering_edge_info
1728+
if !tail_is_copy
1729+
&& let Some(last_subgraph_entering_edge_info) =
1730+
&to_advance.last_subgraph_entering_edge_info
17301731
{
17311732
let Some(last_subgraph_entering_edge) =
17321733
to_advance.edges[last_subgraph_entering_edge_info.index].into()

apollo-federation/src/query_plan/query_planner.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,8 +1521,11 @@ type User @join__type(graph: CONNECTOR, key: "id") {
15211521
planner.api_schema().schema(),
15221522
r#"{ user(id: "1") { friends { name } } }"#,
15231523
"op.graphql",
1524-
).unwrap();
1525-
let plan = planner.build_query_plan(&doc, None, Default::default()).unwrap();
1524+
)
1525+
.unwrap();
1526+
let plan = planner
1527+
.build_query_plan(&doc, None, Default::default())
1528+
.unwrap();
15261529
// name IS on the restricted copy, so single fetch
15271530
insta::assert_snapshot!(plan, @r###"
15281531
QueryPlan {
@@ -1544,8 +1547,11 @@ type User @join__type(graph: CONNECTOR, key: "id") {
15441547
planner.api_schema().schema(),
15451548
r#"{ user(id: "1") { friends { name friends { name } } } }"#,
15461549
"op.graphql",
1547-
).unwrap();
1548-
let plan2 = planner.build_query_plan(&doc2, None, Default::default()).unwrap();
1550+
)
1551+
.unwrap();
1552+
let plan2 = planner
1553+
.build_query_plan(&doc2, None, Default::default())
1554+
.unwrap();
15491555
// friends is NOT on the restricted copy, so needs entity resolution
15501556
insta::assert_snapshot!(plan2, @r###"
15511557
QueryPlan {
@@ -1653,8 +1659,11 @@ type User @join__type(graph: CONNECTOR, key: "id") {
16531659
planner.api_schema().schema(),
16541660
r#"{ user(id: "1") { friends { friends { friends { name } } } } }"#,
16551661
"op.graphql",
1656-
).unwrap();
1657-
let plan = planner.build_query_plan(&doc, None, Default::default()).unwrap();
1662+
)
1663+
.unwrap();
1664+
let plan = planner
1665+
.build_query_plan(&doc, None, Default::default())
1666+
.unwrap();
16581667
insta::assert_snapshot!(plan, @r###"
16591668
QueryPlan {
16601669
Sequence {
@@ -1807,7 +1816,9 @@ type User @join__type(graph: CONNECTORS, key: "id") {
18071816
"op.graphql",
18081817
)
18091818
.unwrap();
1810-
let plan = planner.build_query_plan(&doc, None, Default::default()).unwrap();
1819+
let plan = planner
1820+
.build_query_plan(&doc, None, Default::default())
1821+
.unwrap();
18111822
let plan_str = plan.to_string();
18121823

18131824
assert!(

0 commit comments

Comments
 (0)