Skip to content

Commit

Permalink
Merge pull request #3370 from rmosolgo/fix-input-object-validation
Browse files Browse the repository at this point in the history
Fix bug in input object argument validation
  • Loading branch information
Robert Mosolgo committed Mar 4, 2021
2 parents d264d58 + d8b8132 commit efcedef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def on_argument(node, parent)
context.directive_definition.arguments
when GraphQL::Language::Nodes::InputObject
arg_type = context.argument_definition.type.unwrap
if arg_type.is_a?(GraphQL::InputObjectType)
arguments = arg_type.input_fields
if arg_type.kind.input_object?
arguments = arg_type.arguments
else
# This is some kind of error
nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,36 @@
end
end
end

describe "for input properties" do
class InputVariableSchema < GraphQL::Schema
class Input < GraphQL::Schema::InputObject
argument(:id, String, required: true)
end

class FooMutation < GraphQL::Schema::Mutation
field(:foo, String, null: true)
argument(:input, Input, required: true)

def resolve(input:)
{ foo: input.id }
end
end

class Mutation < GraphQL::Schema::Object
field(:foo_mutation, mutation: FooMutation)
end

mutation(Mutation)
end

it "gives a proper error" do
res1 = InputVariableSchema.execute("mutation($id: String) { fooMutation(input: { id: $id }) { foo } }")
assert_equal ["Nullability mismatch on variable $id and argument id (String / String!)"], res1["errors"].map { |e| e["message"] }

res2 = InputVariableSchema.execute("mutation($id: String!) { fooMutation(input: { id: $id }) { foo } }", variables: { id: "abc" })
refute res2.key?("errors")
assert_equal "abc", res2["data"]["fooMutation"]["foo"]
end
end
end

0 comments on commit efcedef

Please sign in to comment.