Skip to content

Commit f2a22df

Browse files
committed
ok
ok ok step 1 ok ok ok display works maybeeeeee ok ok this is better and more readable wip FUCK fix ok fuck this temp ok ok back to all passing expect bench ok ok ok fix ok build works ok ok ok getting there ok
1 parent 7e1c0f6 commit f2a22df

26 files changed

+767
-444
lines changed

Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/dev-cli/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use query_planner::graph::PlannerOverrideContext;
99
use query_planner::planner::best::find_best_combination;
1010
use query_planner::planner::fetch::fetch_graph::build_fetch_graph_from_query_tree;
1111
use query_planner::planner::fetch::fetch_graph::FetchGraph;
12+
use query_planner::planner::fetch::state::MultiTypeFetchStep;
1213
use query_planner::planner::plan_nodes::QueryPlan;
1314
use query_planner::planner::query_plan::build_query_plan_from_fetch_graph;
1415
use query_planner::planner::tree::query_tree::QueryTree;
@@ -124,7 +125,10 @@ fn process_consumer_schema(path: &str) {
124125
println!("{}", consumer_schema.document);
125126
}
126127

127-
fn process_fetch_graph(supergraph_path: &str, operation_path: &str) -> FetchGraph {
128+
fn process_fetch_graph(
129+
supergraph_path: &str,
130+
operation_path: &str,
131+
) -> FetchGraph<MultiTypeFetchStep> {
128132
let (graph, query_tree, supergraph_state) =
129133
process_merged_tree(supergraph_path, operation_path);
130134

lib/query-planner/src/ast/minification/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ pub enum MinificationError {
66
FieldNotFound(String, String),
77
#[error("Unsupported fragment spread")]
88
UnsupportedFragmentSpread,
9-
#[error("Unsupported field in `_entities`: {0}")]
10-
UnsupportedFieldInEntities(String),
9+
#[error("Unsupported field in `_entities`: {0}.{1}")]
10+
UnsupportedFieldInEntities(String, String),
1111
}

lib/query-planner/src/ast/minification/stats.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ fn walk_and_collect_stats(
9090
}
9191

9292
return Err(MinificationError::UnsupportedFieldInEntities(
93+
type_def.name().to_string(),
9394
field.name.clone(),
9495
));
9596
}

lib/query-planner/src/ast/minification/transform.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ fn transform_field(
185185
}
186186

187187
return Err(MinificationError::UnsupportedFieldInEntities(
188+
type_name.to_string(),
188189
field.name.clone(),
189190
));
190191
}

lib/query-planner/src/ast/mismatch_finder.rs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{
77
merge_path::{MergePath, Segment},
88
selection_item::SelectionItem,
99
selection_set::{FieldSelection, SelectionSet},
10-
type_aware_selection::TypeAwareSelection,
1110
},
11+
planner::fetch::{selections::FetchStepSelections, state::MultiTypeFetchStep},
1212
state::{
1313
subgraph_state::{SubgraphDefinition, SubgraphState},
1414
supergraph_state::{SubgraphName, SupergraphState, TypeNode},
@@ -20,46 +20,43 @@ pub struct SelectionMismatchFinder<'a> {
2020
supergraph_state: &'a SupergraphState,
2121
}
2222

23-
type MismatchesFound = Vec<MergePath>;
23+
type MismatchesFound = Vec<(String, MergePath)>;
2424

2525
impl<'a> SelectionMismatchFinder<'a> {
2626
pub fn new(supergraph_state: &'a SupergraphState) -> Self {
2727
Self { supergraph_state }
2828
}
2929

30-
#[instrument(level = "trace", skip_all, fields(
31-
subgraph_name,
32-
selection = format!("{}", selection_set)
33-
))]
30+
#[instrument(level = "trace", skip_all, fields(subgraph_name,))]
3431
pub fn find_mismatches_in_node(
3532
&self,
3633
subgraph_name: &SubgraphName,
37-
selection_set: &TypeAwareSelection,
34+
selections: &FetchStepSelections<MultiTypeFetchStep>,
3835
) -> MismatchesFound {
39-
let subgraph_state = self
40-
.supergraph_state
41-
.subgraphs_state
42-
.get(subgraph_name)
43-
.unwrap();
44-
45-
let entrypoint_type = subgraph_state
46-
.definitions
47-
.get(&selection_set.type_name)
48-
.unwrap();
49-
5036
let mut mismtaches_found = MismatchesFound::new();
51-
let start_path = MergePath::default();
5237

53-
handle_selection_set(
54-
self.supergraph_state,
55-
subgraph_state,
56-
entrypoint_type,
57-
&selection_set.selection_set,
58-
start_path,
59-
&mut mismtaches_found,
60-
);
61-
62-
trace!("found total of {} mismatches", mismtaches_found.len(),);
38+
for (definition_name, selection_set) in selections.iter_selections() {
39+
let subgraph_state = self
40+
.supergraph_state
41+
.subgraphs_state
42+
.get(subgraph_name)
43+
.unwrap();
44+
45+
let entrypoint_type = subgraph_state.definitions.get(definition_name).unwrap();
46+
let start_path = MergePath::default();
47+
48+
handle_selection_set(
49+
definition_name,
50+
self.supergraph_state,
51+
subgraph_state,
52+
entrypoint_type,
53+
selection_set,
54+
start_path,
55+
&mut mismtaches_found,
56+
);
57+
58+
trace!("found total of {} mismatches", mismtaches_found.len());
59+
}
6360

6461
mismtaches_found
6562
}
@@ -73,6 +70,7 @@ impl<'a> SelectionMismatchFinder<'a> {
7370
selection = format!("{}", selection_set)
7471
))]
7572
fn handle_selection_set<'field, 'schema>(
73+
root_def_type_name: &str,
7674
supergraph_state: &'schema SupergraphState,
7775
subgraph_state: &'schema SubgraphState,
7876
parent_def: &'schema SubgraphDefinition,
@@ -105,6 +103,7 @@ fn handle_selection_set<'field, 'schema>(
105103
));
106104

107105
let next_parent_type_name = handle_field(
106+
root_def_type_name,
108107
supergraph_state,
109108
type_def,
110109
field,
@@ -117,6 +116,7 @@ fn handle_selection_set<'field, 'schema>(
117116
next_parent_type_name.and_then(|n| subgraph_state.definitions.get(n))
118117
{
119118
handle_selection_set(
119+
root_def_type_name,
120120
supergraph_state,
121121
subgraph_state,
122122
next_parent_def,
@@ -156,6 +156,7 @@ fn handle_selection_set<'field, 'schema>(
156156
///
157157
/// Returns the return type of the selection, if the inner selection needs to be processed (in case nested selections are defined).
158158
fn handle_field<'field, 'schema>(
159+
root_def_type_name: &str,
159160
state: &'schema SupergraphState,
160161
parent_def: &'schema SubgraphDefinition,
161162
field: &'field FieldSelection,
@@ -201,7 +202,7 @@ fn handle_field<'field, 'schema>(
201202
field_path,
202203
);
203204

204-
mismatches_found.push(field_path.clone());
205+
mismatches_found.push((root_def_type_name.to_string(), field_path.clone()));
205206
}
206207
}
207208
} else {

lib/query-planner/src/ast/type_aware_selection.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{fmt::Display, hash::Hash};
22

33
use crate::ast::{
44
merge_path::{Condition, Segment},
5-
safe_merge::{AliasesRecords, SafeSelectionSetMerger},
5+
// safe_merge::{AliasesRecords, SafeSelectionSetMerger},
66
selection_set::{FieldSelection, InlineFragmentSelection},
77
};
88

@@ -96,31 +96,31 @@ impl TypeAwareSelection {
9696
}
9797
}
9898

99-
pub fn add_at_path_and_solve_conflicts(
100-
&mut self,
101-
to_add: &Self,
102-
add_at_fetch_path: MergePath,
103-
(self_used_for_requires, other_used_for_requires): (bool, bool),
104-
as_first: bool,
105-
) -> Option<AliasesRecords> {
106-
if let Some(source) =
107-
find_selection_set_by_path_mut(&mut self.selection_set, &add_at_fetch_path)
108-
{
109-
let mut merger = SafeSelectionSetMerger::default();
110-
let aliases_made = merger.merge_selection_set(
111-
source,
112-
&to_add.selection_set,
113-
(self_used_for_requires, other_used_for_requires),
114-
as_first,
115-
);
116-
117-
if !aliases_made.is_empty() {
118-
return Some(aliases_made);
119-
}
120-
}
121-
122-
None
123-
}
99+
// pub fn add_at_path_and_solve_conflicts(
100+
// &mut self,
101+
// to_add: &Self,
102+
// add_at_fetch_path: MergePath,
103+
// (self_used_for_requires, other_used_for_requires): (bool, bool),
104+
// as_first: bool,
105+
// ) -> Option<AliasesRecords> {
106+
// if let Some(source) =
107+
// find_selection_set_by_path_mut(&mut self.selection_set, &add_at_fetch_path)
108+
// {
109+
// let mut merger = SafeSelectionSetMerger::default();
110+
// let aliases_made = merger.merge_selection_set(
111+
// source,
112+
// &to_add.selection_set,
113+
// (self_used_for_requires, other_used_for_requires),
114+
// as_first,
115+
// );
116+
117+
// if !aliases_made.is_empty() {
118+
// return Some(aliases_made);
119+
// }
120+
// }
121+
122+
// None
123+
// }
124124

125125
pub fn has_typename_at_path(&self, lookup_path: &MergePath) -> bool {
126126
find_selection_set_by_path(
@@ -154,15 +154,15 @@ fn selection_item_is_subset_of(source: &SelectionItem, target: &SelectionItem) -
154154
}
155155
}
156156

157-
fn selection_items_are_subset_of(source: &[SelectionItem], target: &[SelectionItem]) -> bool {
157+
pub fn selection_items_are_subset_of(source: &[SelectionItem], target: &[SelectionItem]) -> bool {
158158
target.iter().all(|target_node| {
159159
source
160160
.iter()
161161
.any(|source_node| selection_item_is_subset_of(source_node, target_node))
162162
})
163163
}
164164

165-
fn merge_selection_set(target: &mut SelectionSet, source: &SelectionSet, as_first: bool) {
165+
pub fn merge_selection_set(target: &mut SelectionSet, source: &SelectionSet, as_first: bool) {
166166
if source.items.is_empty() {
167167
return;
168168
}

0 commit comments

Comments
 (0)