@@ -106,6 +106,12 @@ impl<'a> std::fmt::Display for SelectedFields<'a> {
106106/// A GraphQL query that has been preprocessed and checked and is ready
107107/// for execution. Checking includes validating all query fields and, if
108108/// desired, checking the query's complexity
109+ //
110+ // The implementation contains various workarounds to make it compatible
111+ // with the previous implementation when it comes to queries that are not
112+ // fully spec compliant and should be rejected through rigorous validation
113+ // against the GraphQL spec. Once we do validate queries, code that is
114+ // marked with `graphql-bug-compat` can be deleted.
109115pub struct Query {
110116 /// The schema against which to execute the query
111117 pub schema : Arc < ApiSchema > ,
@@ -791,6 +797,7 @@ impl Transform {
791797
792798 let resolver = |name : & str | self . schema . get_named_type ( name) ;
793799
800+ let mut defined_args: usize = 0 ;
794801 for argument_def in sast:: get_argument_definitions ( ty, field_name)
795802 . into_iter ( )
796803 . flatten ( )
@@ -799,6 +806,9 @@ impl Transform {
799806 . iter_mut ( )
800807 . find ( |arg| & arg. 0 == & argument_def. name )
801808 . map ( |arg| & mut arg. 1 ) ;
809+ if arg_value. is_some ( ) {
810+ defined_args += 1 ;
811+ }
802812 match coercion:: coerce_input_value (
803813 arg_value. as_deref ( ) . cloned ( ) ,
804814 & argument_def,
@@ -820,6 +830,18 @@ impl Transform {
820830 }
821831 }
822832
833+ // see: graphql-bug-compat
834+ // avoids error 'unknown argument on field'
835+ if defined_args < arguments. len ( ) {
836+ // `arguments` contains undefined arguments, remove them
837+ match sast:: get_argument_definitions ( ty, field_name) {
838+ None => arguments. clear ( ) ,
839+ Some ( arg_defs) => {
840+ arguments. retain ( |( name, _) | arg_defs. iter ( ) . any ( |def| & def. name == name) )
841+ }
842+ }
843+ }
844+
823845 if errors. is_empty ( ) {
824846 Ok ( ( ) )
825847 } else {
0 commit comments