@@ -176,30 +176,33 @@ def validate_non_null_input(input, ctx, max_errors: nil)
176176 return GraphQL ::Query ::InputValidationResult . from_problem ( INVALID_OBJECT_MESSAGE % { object : JSON . generate ( input , quirks_mode : true ) } )
177177 end
178178
179- # Inject missing required arguments
180- missing_required_inputs = ctx . types . arguments ( self ) . reduce ( { } ) do |m , ( argument ) |
181- if !input . key? ( argument . graphql_name ) && argument . type . non_null? && !argument . default_value? && types . argument ( self , argument . graphql_name )
182- m [ argument . graphql_name ] = nil
183- end
184-
185- m
186- end
187179
188180 result = nil
189- [ input , missing_required_inputs ] . each do |args_to_validate |
190- args_to_validate . each do |argument_name , value |
191- argument = types . argument ( self , argument_name )
192- # Items in the input that are unexpected
193- if argument . nil?
194- result ||= Query ::InputValidationResult . new
195- result . add_problem ( "Field is not defined on #{ self . graphql_name } " , [ argument_name ] )
196- else
197- # Items in the input that are expected, but have invalid values
198- argument_result = argument . type . validate_input ( value , ctx )
181+
182+
183+ input . each do |argument_name , value |
184+ argument = types . argument ( self , argument_name )
185+ # Items in the input that are unexpected
186+ if argument . nil?
187+ result ||= Query ::InputValidationResult . new
188+ result . add_problem ( "Field is not defined on #{ self . graphql_name } " , [ argument_name ] )
189+ else
190+ # Items in the input that are expected, but have invalid values
191+ argument_result = argument . type . validate_input ( value , ctx )
192+ if !argument_result . valid?
199193 result ||= Query ::InputValidationResult . new
200- if !argument_result . valid?
201- result . merge_result! ( argument_name , argument_result )
202- end
194+ result . merge_result! ( argument_name , argument_result )
195+ end
196+ end
197+ end
198+
199+ # Check for missing non-null arguments
200+ ctx . types . arguments ( self ) . each do |argument |
201+ if !input . key? ( argument . graphql_name ) && argument . type . non_null? && !argument . default_value?
202+ result ||= Query ::InputValidationResult . new
203+ argument_result = argument . type . validate_input ( nil , ctx )
204+ if !argument_result . valid?
205+ result . merge_result! ( argument . graphql_name , argument_result )
203206 end
204207 end
205208 end
0 commit comments