File tree 2 files changed +44
-0
lines changed
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -739,6 +739,7 @@ impl Transform {
739
739
740
740
let resolver = |name : & str | self . schema . get_named_type ( name) ;
741
741
742
+ let mut defined_args: usize = 0 ;
742
743
for argument_def in sast:: get_argument_definitions ( ty, field_name)
743
744
. into_iter ( )
744
745
. flatten ( )
@@ -747,6 +748,9 @@ impl Transform {
747
748
. iter_mut ( )
748
749
. find ( |arg| & arg. 0 == & argument_def. name )
749
750
. map ( |arg| & mut arg. 1 ) ;
751
+ if arg_value. is_some ( ) {
752
+ defined_args += 1 ;
753
+ }
750
754
match coercion:: coerce_input_value (
751
755
arg_value. as_deref ( ) . cloned ( ) ,
752
756
& argument_def,
@@ -768,6 +772,16 @@ impl Transform {
768
772
}
769
773
}
770
774
775
+ if defined_args < arguments. len ( ) {
776
+ // `arguments` contains undefined arguments, remove them
777
+ match sast:: get_argument_definitions ( ty, field_name) {
778
+ None => arguments. clear ( ) ,
779
+ Some ( arg_defs) => {
780
+ arguments. retain ( |( name, _) | arg_defs. iter ( ) . any ( |def| & def. name == name) )
781
+ }
782
+ }
783
+ }
784
+
771
785
if errors. is_empty ( ) {
772
786
Ok ( ( ) )
773
787
} else {
Original file line number Diff line number Diff line change @@ -1420,6 +1420,36 @@ fn can_use_nested_filter() {
1420
1420
} )
1421
1421
}
1422
1422
1423
+ #[ test]
1424
+ fn ignores_invalid_field_arguments ( ) {
1425
+ run_test_sequentially ( |store| async move {
1426
+ let deployment = setup ( store. as_ref ( ) ) ;
1427
+ // This query has to return all the musicians since `id` is not a
1428
+ // valid argument for the `musicians` field and must therefore be
1429
+ // ignored
1430
+ let result = execute_query_document (
1431
+ & deployment. hash ,
1432
+ graphql_parser:: parse_query ( "query { musicians(id: \" m1\" ) { id } } " )
1433
+ . expect ( "invalid test query" )
1434
+ . into_static ( ) ,
1435
+ )
1436
+ . await ;
1437
+
1438
+ let data = extract_data ! ( result) . unwrap ( ) ;
1439
+ match data {
1440
+ r:: Value :: Object ( obj) => match obj. get ( "musicians" ) . unwrap ( ) {
1441
+ r:: Value :: List ( lst) => {
1442
+ assert_eq ! ( 4 , lst. len( ) ) ;
1443
+ }
1444
+ _ => panic ! ( "expected a list of values" ) ,
1445
+ } ,
1446
+ _ => {
1447
+ panic ! ( "expected an object" )
1448
+ }
1449
+ }
1450
+ } )
1451
+ }
1452
+
1423
1453
async fn check_musicians_at (
1424
1454
id : & DeploymentHash ,
1425
1455
query : & str ,
You can’t perform that action at this time.
0 commit comments