Skip to content

Commit 902befe

Browse files
committed
Also require at least one argument for input objects
1 parent 2c6b7a8 commit 902befe

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/graphql/schema/validation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def self.assert_named_items_are_valid(item_name, get_items_proc)
106106

107107
HAS_AT_LEAST_ONE_FIELD = Rules.count_at_least("field", 1, ->(type) { type.all_fields })
108108
FIELDS_ARE_VALID = Rules.assert_named_items_are_valid("field", ->(type) { type.all_fields })
109+
HAS_AT_LEAST_ONE_ARGUMENT = Rules.count_at_least("argument", 1, ->(type) { type.arguments })
109110

110111
HAS_ONE_OR_MORE_POSSIBLE_TYPES = ->(type) {
111112
type.possible_types.length >= 1 ? nil : "must have at least one possible type"
@@ -279,6 +280,7 @@ def self.assert_named_items_are_valid(item_name, get_items_proc)
279280
Rules::INTERFACES_ARE_IMPLEMENTED,
280281
],
281282
GraphQL::InputObjectType => [
283+
Rules::HAS_AT_LEAST_ONE_ARGUMENT,
282284
Rules::ARGUMENTS_ARE_STRING_TO_ARGUMENT,
283285
Rules::ARGUMENTS_ARE_VALID,
284286
],

spec/graphql/schema/validation_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,22 @@ def assert_validation_warns(object, warning)
276276
end
277277
}
278278

279+
let(:no_arguments_input) {
280+
GraphQL::InputObjectType.define do
281+
name "NoArguments"
282+
end
283+
}
279284
it "requires {String => Argument} arguments" do
280285
assert_error_includes invalid_arguments_input, "map String => GraphQL::Argument, not #{integer_class_name} => Symbol"
281286
end
282287

283288
it "applies validation to its member Arguments" do
284289
assert_error_includes invalid_argument_member_input, "default value [\"xyz\"] is not valid for type Float"
285290
end
291+
292+
it "requires one argument" do
293+
assert_error_includes no_arguments_input, "must define at least 1 argument"
294+
end
286295
end
287296

288297
describe "validating InterfaceTypes" do

0 commit comments

Comments
 (0)