Skip to content

Commit

Permalink
Fix enums and input objects in a more clever way
Browse files Browse the repository at this point in the history
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?
  • Loading branch information
eapache committed Apr 27, 2021
1 parent b4b6255 commit 963b205
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/graphql/schema/argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ def validate_input_type(input_type, wrapped: false)
end

def validate_default_value(default_value, input_type)
raise "BOOM" unless input_type.valid_input?(default_value, GraphQL::Query::NullContext.new)
default_value = input_type.coerce_isolated_result(default_value) unless default_value.nil?
raise "BOOM" unless input_type.valid_isolated_input?(default_value)
end

def validate_deprecated_or_optional(null:, deprecation_reason:)
Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/schema/input_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def coerce_input(value, ctx)
# It's funny to think of a _result_ of an input object.
# This is used for rendering the default value in introspection responses.
def coerce_result(value, ctx)
# Allow the application to provide values as :symbols, and convert them to the strings
value = value.reduce({}) { |memo, (k, v)| memo[k.to_s] = v; memo }
# Allow the application to provide values as :snake_symbols, and convert them to the camelStrings
value = value.reduce({}) { |memo, (k, v)| memo[Member::BuildType.camelize(k.to_s)] = v; memo }

result = {}

Expand Down

0 comments on commit 963b205

Please sign in to comment.