Skip to content

Commit 232b584

Browse files
committed
Delay input type validation for late-bound types
1 parent c0b79e6 commit 232b584

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

lib/graphql/schema/argument.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ def to_graphql
146146
argument
147147
end
148148

149-
attr_writer :type
149+
def type=(new_type)
150+
validate_input_type(new_type)
151+
@type = new_type
152+
end
150153

151154
def type
152155
@type ||= begin
@@ -155,10 +158,7 @@ def type
155158
rescue StandardError => err
156159
raise ArgumentError, "Couldn't build type for Argument #{@owner.name}.#{name}: #{err.class.name}: #{err.message}", err.backtrace
157160
end
158-
unwrapped_parsed_type = parsed_type.unwrap
159-
if !unwrapped_parsed_type.kind.input?
160-
raise ArgumentError, "Invalid input type for #{path}: #{unwrapped_parsed_type.graphql_name}. Must be scalar, enum, or input object, not #{unwrapped_parsed_type.kind.name}."
161-
end
161+
validate_input_type(parsed_type)
162162
parsed_type
163163
end
164164
end
@@ -195,6 +195,18 @@ def prepare_value(obj, value, context: nil)
195195
raise "Invalid prepare for #{@owner.name}.name: #{@prepare.inspect}"
196196
end
197197
end
198+
199+
def validate_input_type(input_type)
200+
if input_type.is_a?(String) || input_type.is_a?(GraphQL::Schema::LateBoundType)
201+
# Do nothing; assume this will be validated later
202+
elsif input_type.kind.non_null? || input_type.kind.list?
203+
validate_input_type(input_type.unwrap)
204+
elsif !input_type.kind.input?
205+
raise ArgumentError, "Invalid input type for #{path}: #{input_type.graphql_name}. Must be scalar, enum, or input object, not #{input_type.kind.name}."
206+
else
207+
# It's an input type, we're OK
208+
end
209+
end
198210
end
199211
end
200212
end

0 commit comments

Comments
 (0)