File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -739,6 +739,7 @@ impl Transform {
739739
740740 let resolver = |name : & str | self . schema . get_named_type ( name) ;
741741
742+ let mut defined_args: usize = 0 ;
742743 for argument_def in sast:: get_argument_definitions ( ty, field_name)
743744 . into_iter ( )
744745 . flatten ( )
@@ -747,6 +748,9 @@ impl Transform {
747748 . iter_mut ( )
748749 . find ( |arg| & arg. 0 == & argument_def. name )
749750 . map ( |arg| & mut arg. 1 ) ;
751+ if arg_value. is_some ( ) {
752+ defined_args += 1 ;
753+ }
750754 match coercion:: coerce_input_value (
751755 arg_value. as_deref ( ) . cloned ( ) ,
752756 & argument_def,
@@ -768,6 +772,16 @@ impl Transform {
768772 }
769773 }
770774
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+
771785 if errors. is_empty ( ) {
772786 Ok ( ( ) )
773787 } else {
Original file line number Diff line number Diff line change @@ -1420,6 +1420,36 @@ fn can_use_nested_filter() {
14201420 } )
14211421}
14221422
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+
14231453async fn check_musicians_at (
14241454 id : & DeploymentHash ,
14251455 query : & str ,
You can’t perform that action at this time.
0 commit comments