@@ -106,6 +106,12 @@ impl<'a> std::fmt::Display for SelectedFields<'a> {
106
106
/// A GraphQL query that has been preprocessed and checked and is ready
107
107
/// for execution. Checking includes validating all query fields and, if
108
108
/// 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.
109
115
pub struct Query {
110
116
/// The schema against which to execute the query
111
117
pub schema : Arc < ApiSchema > ,
@@ -791,6 +797,7 @@ impl Transform {
791
797
792
798
let resolver = |name : & str | self . schema . get_named_type ( name) ;
793
799
800
+ let mut defined_args: usize = 0 ;
794
801
for argument_def in sast:: get_argument_definitions ( ty, field_name)
795
802
. into_iter ( )
796
803
. flatten ( )
@@ -799,6 +806,9 @@ impl Transform {
799
806
. iter_mut ( )
800
807
. find ( |arg| & arg. 0 == & argument_def. name )
801
808
. map ( |arg| & mut arg. 1 ) ;
809
+ if arg_value. is_some ( ) {
810
+ defined_args += 1 ;
811
+ }
802
812
match coercion:: coerce_input_value (
803
813
arg_value. as_deref ( ) . cloned ( ) ,
804
814
& argument_def,
@@ -820,6 +830,18 @@ impl Transform {
820
830
}
821
831
}
822
832
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
+
823
845
if errors. is_empty ( ) {
824
846
Ok ( ( ) )
825
847
} else {
0 commit comments