Skip to content

Commit 963b205

Browse files
committed
Fix enums and input objects in a more clever way
They're basically being specified as return values (i.e. on the ruby side of the ruby/wire-format divide) so coerce them to results before validating. Also fix InputObject#coerce_result to handle camelizing keys. I _think_ this makes sense?
1 parent b4b6255 commit 963b205

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/graphql/schema/argument.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ def validate_input_type(input_type, wrapped: false)
317317
end
318318

319319
def validate_default_value(default_value, input_type)
320-
raise "BOOM" unless input_type.valid_input?(default_value, GraphQL::Query::NullContext.new)
320+
default_value = input_type.coerce_isolated_result(default_value) unless default_value.nil?
321+
raise "BOOM" unless input_type.valid_isolated_input?(default_value)
321322
end
322323

323324
def validate_deprecated_or_optional(null:, deprecation_reason:)

lib/graphql/schema/input_object.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ def coerce_input(value, ctx)
226226
# It's funny to think of a _result_ of an input object.
227227
# This is used for rendering the default value in introspection responses.
228228
def coerce_result(value, ctx)
229-
# Allow the application to provide values as :symbols, and convert them to the strings
230-
value = value.reduce({}) { |memo, (k, v)| memo[k.to_s] = v; memo }
229+
# Allow the application to provide values as :snake_symbols, and convert them to the camelStrings
230+
value = value.reduce({}) { |memo, (k, v)| memo[Member::BuildType.camelize(k.to_s)] = v; memo }
231231

232232
result = {}
233233

0 commit comments

Comments
 (0)