Skip to content

Commit 3f426b6

Browse files
committed
ok
1 parent c34d48f commit 3f426b6

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

lib/query-planner/src/planner/fetch/selections.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,16 @@ impl<State> FetchStepSelections<State> {
125125
selection_set: SelectionSet,
126126
as_first: bool,
127127
) {
128+
println!(
129+
"add_at_path_inner, definition_name: {}, fetch_path: {:?}",
130+
definition_name, fetch_path
131+
);
128132
let current = self
129133
.selections_for_definition_mut(&definition_name)
130-
.expect("no selections declared for definition");
134+
.expect(&format!(
135+
"no selections declared for definition: {}",
136+
definition_name
137+
));
131138

132139
if let Some(selection_at_path) = find_selection_set_by_path_mut(current, fetch_path) {
133140
merge_selection_set(selection_at_path, &selection_set, as_first);
@@ -141,18 +148,24 @@ impl<State> FetchStepSelections<State> {
141148
}
142149

143150
impl FetchStepSelections<MultiTypeFetchStep> {
151+
pub fn try_as_single(&self) -> Option<&str> {
152+
if self.selections.len() == 1 {
153+
self.selections.keys().next().map(|key| key.as_str())
154+
} else {
155+
None
156+
}
157+
}
158+
144159
pub fn iter_selections(&self) -> impl Iterator<Item = (&String, &SelectionSet)> {
145160
self.selections.iter()
146161
}
147162

148163
pub fn migrate_from_another(&mut self, other: &Self, fetch_path: &MergePath) {
149-
for (definition_name, selection_set) in other.iter_selections() {
150-
println!(
151-
"migrate_from_another, fetch_path: {}, definition_name={}",
152-
fetch_path, definition_name
153-
);
164+
let maybe_merge_into = self.try_as_single().map(|str| str.to_string());
154165

155-
self.add_at_path_inner(definition_name, fetch_path, selection_set.clone(), false);
166+
for (definition_name, selection_set) in other.iter_selections() {
167+
let target_type = maybe_merge_into.as_ref().unwrap_or(definition_name);
168+
self.add_at_path_inner(&target_type, fetch_path, selection_set.clone(), false);
156169
}
157170
}
158171

0 commit comments

Comments
 (0)