diff --git a/lib/graphql/schema/argument.rb b/lib/graphql/schema/argument.rb index 7f38fea5c5..214d6c6ef9 100644 --- a/lib/graphql/schema/argument.rb +++ b/lib/graphql/schema/argument.rb @@ -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 diff --git a/spec/graphql/schema/argument_spec.rb b/spec/graphql/schema/argument_spec.rb index d8d5024306..080c8565f8 100644 --- a/spec/graphql/schema/argument_spec.rb +++ b/spec/graphql/schema/argument_spec.rb @@ -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