@@ -200,25 +200,22 @@ where
200
200
variable_definitions,
201
201
) ?;
202
202
203
- let insert_type : OnConflictType = match field. get_arg ( "onConflict" ) {
203
+ let conflict_type : OnConflictType = match field. get_arg ( "onConflict" ) {
204
204
None => return Ok ( None ) ,
205
205
Some ( x) => match x. type_ ( ) . unmodified_type ( ) {
206
206
__Type:: OnConflictInput ( insert_on_conflict) => insert_on_conflict,
207
207
_ => return Err ( "Could not locate Insert Entity type" . to_string ( ) ) ,
208
208
} ,
209
209
} ;
210
210
211
- let filter: FilterBuilder =
212
- read_argument_filter ( field, query_field, variables, variable_definitions) ?;
213
-
214
211
let on_conflict_builder = match validated {
215
212
gson:: Value :: Absent | gson:: Value :: Null => None ,
216
213
gson:: Value :: Object ( contents) => {
217
214
let constraint = match contents
218
215
. get ( "constraint" )
219
216
. expect ( "OnConflict revalidation error. Expected constraint" )
220
217
{
221
- gson:: Value :: String ( ix_name) => insert_type
218
+ gson:: Value :: String ( ix_name) => conflict_type
222
219
. table
223
220
. indexes
224
221
. iter ( )
@@ -231,6 +228,36 @@ where
231
228
}
232
229
} ;
233
230
231
+ // TODO: Filter reading logic is partially duplicated from read_argument_filter
232
+ // ideally this should be refactored
233
+ let filter_gson = contents
234
+ . get ( "filter" )
235
+ . expect ( "onConflict revalidation error" ) ;
236
+
237
+ let filter = match filter_gson {
238
+ gson:: Value :: Null | gson:: Value :: Absent => FilterBuilder { elems : vec ! [ ] } ,
239
+ gson:: Value :: Object ( _) => {
240
+ let filter_type = conflict_type
241
+ . input_fields ( )
242
+ . expect ( "Failed to unwrap input fields on OnConflict type" )
243
+ . iter ( )
244
+ . find ( |in_f| in_f. name ( ) == "filter" )
245
+ . expect ( "Failed to get filter input_field on onConflict type" )
246
+ . type_ ( )
247
+ . unmodified_type ( ) ;
248
+
249
+ if !matches ! ( filter_type, __Type:: FilterEntity ( _) ) {
250
+ return Err ( "Could not locate Filter Entity type" . to_string ( ) ) ;
251
+ }
252
+ let filter_field_map = input_field_map ( & filter_type) ;
253
+ let filter_elems = create_filters ( & filter_gson, & filter_field_map) ?;
254
+ FilterBuilder {
255
+ elems : filter_elems,
256
+ }
257
+ }
258
+ _ => return Err ( "OnConflict revalidation error. invalid filter object" . to_string ( ) ) ,
259
+ } ;
260
+
234
261
let update_fields = match contents
235
262
. get ( "updateFields" )
236
263
. expect ( "OnConflict revalidation error. Expected updateFields" )
@@ -240,7 +267,7 @@ where
240
267
for col_name in col_names {
241
268
match col_name {
242
269
gson:: Value :: String ( c) => {
243
- let col = insert_type . table . columns . iter ( ) . find ( |column| & column. name == c) . expect ( "OnConflict revalidation error. updateFields: unknown column name" ) ;
270
+ let col = conflict_type . table . columns . iter ( ) . find ( |column| & column. name == c) . expect ( "OnConflict revalidation error. updateFields: unknown column name" ) ;
244
271
update_columns. insert ( Arc :: clone ( col) ) ;
245
272
}
246
273
_ => return Err ( "OnConflict revalidation error. Expected updateFields to be column names" . to_string ( ) ) ,
@@ -1145,11 +1172,14 @@ where
1145
1172
variable_definitions,
1146
1173
) ?;
1147
1174
1175
+ //return Err(format!("Err {:?}", validated));
1176
+
1148
1177
let filter_type = field
1149
1178
. get_arg ( "filter" )
1150
1179
. expect ( "failed to get filter argument" )
1151
1180
. type_ ( )
1152
1181
. unmodified_type ( ) ;
1182
+
1153
1183
if !matches ! ( filter_type, __Type:: FilterEntity ( _) ) {
1154
1184
return Err ( "Could not locate Filter Entity type" . to_string ( ) ) ;
1155
1185
}
0 commit comments