diff --git a/lib/graphql/schema/traversal.rb b/lib/graphql/schema/traversal.rb index 8c6759b98e..eac4448bc6 100644 --- a/lib/graphql/schema/traversal.rb +++ b/lib/graphql/schema/traversal.rb @@ -139,7 +139,7 @@ def visit(schema, member, context_description) prev_type = @type_map[type_defn.name] # Continue to visit this type if it's the first time we've seen it: if prev_type.nil? - validate_type(type_defn, context_description) + validate_type(type_defn) @type_map[type_defn.name] = type_defn case type_defn when GraphQL::ObjectType @@ -217,10 +217,10 @@ def visit_field_on_type(schema, type_defn, field_defn, dynamic_field: false) GraphQL::Query::Arguments.construct_arguments_class(instrumented_field_defn) end - def validate_type(member, context_description) - error_message = GraphQL::Schema::Validation.validate(member) + def validate_type(type) + error_message = GraphQL::Schema::Validation.validate(type) if error_message - raise GraphQL::Schema::InvalidTypeError.new("#{context_description} is invalid: #{error_message}") + raise GraphQL::Schema::InvalidTypeError.new("#{type.name} is invalid: #{error_message}") end end end diff --git a/spec/graphql/schema/traversal_spec.rb b/spec/graphql/schema/traversal_spec.rb index d87e9246a9..0dd1a1a0df 100644 --- a/spec/graphql/schema/traversal_spec.rb +++ b/spec/graphql/schema/traversal_spec.rb @@ -97,6 +97,28 @@ def traversal(types) it "raises an InvalidTypeError when passed an object that isnt a GraphQL::BaseType" do assert_raises(GraphQL::Schema::InvalidTypeError) { traversal([another_invalid_type]) } end + + it "raises an InvalidTypeError for object field arguments referencing invalid input objects" do + other_type = GraphQL::ObjectType.define do + name "MyOtherType" + field :someField, GraphQL::STRING_TYPE + end + + invalid_input_type = GraphQL::InputObjectType.define do + name "MyInput" + input_field :someField, other_type + end + + type = GraphQL::ObjectType.define do + name "MyType" + field :anotherField, !GraphQL::STRING_TYPE do |field| + field.argument :anArgument, invalid_input_type + end + end + + error = assert_raises(GraphQL::Schema::InvalidTypeError) { traversal([type]) } + assert_equal("MyInput is invalid: argument \"someField\" type must be a valid input type (Scalar or InputObject), not GraphQL::ObjectType (MyOtherType)", error.message) + end end describe "when a schema has multiple types with the same name" do