Skip to content

Commit 9ec42cb

Browse files
committed
FF
1 parent df5ee7e commit 9ec42cb

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

lib/executor/src/utils/traverse.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ pub fn traverse_and_callback_mut<'a, Callback>(
2020
// If the path is empty, we call the callback on each item in the array
2121
// We iterate because we want the entity objects directly
2222
for (index, item) in arr.iter_mut().enumerate() {
23-
let current_error_path_for_index =
24-
current_error_path.as_ref().map(|current_path| {
25-
let mut path = current_path.clone();
26-
path.push(GraphQLErrorPathSegment::Index(index));
27-
path
28-
});
23+
let current_error_path_for_index: Option<Vec<GraphQLErrorPathSegment>> =
24+
extend_error_path_with_index(&current_error_path, index);
2925
callback(item, current_error_path_for_index);
3026
}
3127
} else {
@@ -42,13 +38,7 @@ pub fn traverse_and_callback_mut<'a, Callback>(
4238
let rest_of_path = &remaining_path[1..];
4339
for (index, item) in arr.iter_mut().enumerate() {
4440
let current_error_path_for_index =
45-
current_error_path
46-
.as_ref()
47-
.map(|current_error_path_for_index| {
48-
let mut path = current_error_path_for_index.clone();
49-
path.push(GraphQLErrorPathSegment::Index(index));
50-
path
51-
});
41+
extend_error_path_with_index(&current_error_path, index);
5242
traverse_and_callback_mut(
5343
item,
5444
rest_of_path,
@@ -106,13 +96,7 @@ pub fn traverse_and_callback_mut<'a, Callback>(
10696
// If the current data is an array, we need to check each item
10797
for (index, item) in arr.iter_mut().enumerate() {
10898
let current_error_path_for_index =
109-
current_error_path
110-
.as_ref()
111-
.map(|current_error_path_for_index| {
112-
let mut path = current_error_path_for_index.clone();
113-
path.push(GraphQLErrorPathSegment::Index(index));
114-
path
115-
});
99+
extend_error_path_with_index(&current_error_path, index);
116100
traverse_and_callback_mut(
117101
item,
118102
remaining_path,
@@ -126,6 +110,17 @@ pub fn traverse_and_callback_mut<'a, Callback>(
126110
}
127111
}
128112

113+
fn extend_error_path_with_index(
114+
current_error_path: &Option<Vec<GraphQLErrorPathSegment>>,
115+
index: usize,
116+
) -> Option<Vec<GraphQLErrorPathSegment>> {
117+
current_error_path.as_ref().map(|path| {
118+
let mut new_path = path.clone();
119+
new_path.push(GraphQLErrorPathSegment::Index(index));
120+
new_path
121+
})
122+
}
123+
129124
pub fn traverse_and_callback<'a, E, Callback>(
130125
current_data: &'a Value<'a>,
131126
remaining_path: &'a [FlattenNodePathSegment],

0 commit comments

Comments
 (0)