@@ -8,7 +8,7 @@ use crate::core::jit::builder::Builder;
8
8
use crate :: core:: jit:: store:: Store ;
9
9
use crate :: core:: jit:: synth:: Synth ;
10
10
use crate :: core:: jit:: transform:: InputResolver ;
11
- use crate :: core:: jit:: { transform, OperationPlan , Variables } ;
11
+ use crate :: core:: jit:: { transform, Field , OperationPlan , Variables } ;
12
12
use crate :: core:: json:: { JsonLike , JsonObjectLike } ;
13
13
use crate :: core:: valid:: Validator ;
14
14
use crate :: core:: Transform ;
@@ -119,10 +119,11 @@ impl<'a, Value: Deserialize<'a> + Clone + 'a + JsonLike<'a> + std::fmt::Debug> J
119
119
let ProcessedTestData { posts, users } = self . test_data . to_processed ( ) ;
120
120
let vars = self . vars . clone ( ) ;
121
121
122
- let posts_id = self . plan . find_field_path ( & [ "posts" ] ) . unwrap ( ) . id . to_owned ( ) ;
123
- let users_id = self
124
- . plan
125
- . find_field_path ( & [ "posts" , "user" ] )
122
+ let posts_id = find_field_path ( & self . plan , & [ "posts" ] )
123
+ . unwrap ( )
124
+ . id
125
+ . to_owned ( ) ;
126
+ let users_id = find_field_path ( & self . plan , & [ "posts" , "user" ] )
126
127
. unwrap ( )
127
128
. id
128
129
. to_owned ( ) ;
@@ -137,3 +138,21 @@ impl<'a, Value: Deserialize<'a> + Clone + 'a + JsonLike<'a> + std::fmt::Debug> J
137
138
Synth :: new ( & self . plan , store, vars)
138
139
}
139
140
}
141
+
142
+ /// Search for a field by specified path of nested fields
143
+ pub fn find_field_path < ' a , S : AsRef < str > , T > (
144
+ plan : & ' a OperationPlan < T > ,
145
+ path : & [ S ] ,
146
+ ) -> Option < & ' a Field < T > > {
147
+ match path. split_first ( ) {
148
+ None => None ,
149
+ Some ( ( name, path) ) => {
150
+ let field = plan. iter_dfs ( ) . find ( |field| field. name == name. as_ref ( ) ) ?;
151
+ if path. is_empty ( ) {
152
+ Some ( field)
153
+ } else {
154
+ find_field_path ( plan, path)
155
+ }
156
+ }
157
+ }
158
+ }
0 commit comments