Skip to content

Commit d7e0cb0

Browse files
authored
Merge pull request rmosolgo#4341 from klaudia-janiec/fix-rescue-from
Fix handle_or_reraise with arguments validation
2 parents 10e31f7 + 1ccfdc2 commit d7e0cb0

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

lib/graphql/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ def handle_or_reraise(context, err)
755755
if handler
756756
obj = context[:current_object]
757757
args = context[:current_arguments]
758-
args = args && args.keyword_arguments
758+
args = args && args.respond_to?(:keyword_arguments) ? args.keyword_arguments : nil
759759
field = context[:current_field]
760760
if obj.is_a?(GraphQL::Schema::Object)
761761
obj = obj.object

spec/graphql/schema/argument_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,4 +696,46 @@ def get_echo_for(use_if)
696696
assert_equal "method-default", get_echo_for(:visible_4) # no match
697697
end
698698
end
699+
700+
describe "multiple argument validations with rescue_from" do
701+
let(:schema) do
702+
Class.new(GraphQL::Schema) do
703+
rescue_from(StandardError) do |exception, _obj, _args, _context, _field|
704+
raise exception
705+
end
706+
707+
query_type = Class.new(GraphQL::Schema::Object) do
708+
graphql_name 'TestQueryType'
709+
710+
field :test, Integer, null: false do
711+
argument :a, Integer, validates: { numericality: { greater_than_or_equal_to: 1 } }
712+
argument :b, Integer, validates: { numericality: { greater_than_or_equal_to: 1 } }
713+
end
714+
715+
def test; end
716+
end
717+
718+
query(query_type)
719+
lazy_resolve(Proc, :call)
720+
end
721+
end
722+
723+
it 'validates both arguments' do
724+
expected_errors = [
725+
{
726+
"message"=>"a must be greater than or equal to 1",
727+
"locations"=>[{ "line"=>1, "column"=>3 }],
728+
"path"=>["test"]
729+
},
730+
{
731+
"message"=>"b must be greater than or equal to 1",
732+
"locations"=>[{"line"=>1, "column"=>3}],
733+
"path"=>["test"]
734+
}
735+
]
736+
query = "{ test(a: -4, b: -5) }"
737+
738+
assert_equal expected_errors, schema.execute(query).to_h['errors']
739+
end
740+
end
699741
end

0 commit comments

Comments
 (0)