Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/graphql/schema/argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def initialize(arg_name = nil, type_expr = nil, desc = nil, required: true, type
end

if required == :nullable
self.owner.validates(required: { argument: arg_name })
self.owner.validates(required: { argument: @keyword })
end

if definition_block
Expand Down
29 changes: 29 additions & 0 deletions spec/graphql/schema/argument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,35 @@ def echo(str:)
res = RequiredNullableSchema.execute('{ echo }')
assert_equal ["echo must include the following argument: str."], res["errors"].map { |e| e["message"] }
end

describe "combined with `as:`" do
class RequiredNullableAsSchema < GraphQL::Schema
class Query < GraphQL::Schema::Object
field :echo, String, resolve_static: true do
argument :str, String, required: :nullable, as: :renamed_str
end

def self.echo(context, renamed_str:)
renamed_str.inspect
end

def echo(renamed_str:)
renamed_str.inspect
end
end

query(Query)
end

it "validates against the aliased keyword" do
res = RequiredNullableAsSchema.execute('{ echo(str: "ok") }')
assert_equal "\"ok\"", res["data"]["echo"]
res = RequiredNullableAsSchema.execute('{ echo(str: null) }')
assert_equal "nil", res["data"]["echo"]
res = RequiredNullableAsSchema.execute('{ echo }')
assert_equal ["echo must include the following argument: str."], res["errors"].map { |e| e["message"] }
end
end
end

describe "replace_null_with_default: true" do
Expand Down
Loading