@@ -176,30 +176,32 @@ 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
184179
185- m
180+ result = nil
181+
182+ # Check for missing non-null arguments
183+ ctx . types . arguments ( self ) . each do |argument |
184+ if !input . key? ( argument . graphql_name ) && argument . type . non_null? && !argument . default_value?
185+ result ||= Query ::InputValidationResult . new
186+ argument_result = argument . type . validate_input ( value , ctx )
187+ if !argument_result . valid?
188+ result . merge_result! ( argument_name , argument_result )
189+ end
190+ end
186191 end
187192
188- 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 )
193+ input . each do |argument_name , value |
194+ argument = types . argument ( self , argument_name )
195+ # Items in the input that are unexpected
196+ if argument . nil?
197+ result ||= Query ::InputValidationResult . new
198+ result . add_problem ( "Field is not defined on #{ self . graphql_name } " , [ argument_name ] )
199+ else
200+ # Items in the input that are expected, but have invalid values
201+ argument_result = argument . type . validate_input ( value , ctx )
202+ if !argument_result . valid?
199203 result ||= Query ::InputValidationResult . new
200- if !argument_result . valid?
201- result . merge_result! ( argument_name , argument_result )
202- end
204+ result . merge_result! ( argument_name , argument_result )
203205 end
204206 end
205207 end
0 commit comments