From 1673f69f08223dbf0e448388a9a8d181caa14d0f Mon Sep 17 00:00:00 2001 From: Evan Huus Date: Thu, 29 Apr 2021 19:14:21 +0000 Subject: [PATCH] Fix introspection of default input objects It seems that the intent was to allow default input object values to be specified in snake_case, but we weren't camelCasing them on output which was leading to issues. Tweak an existing spec to cover this case (as well as the "enums specifed as values not names" case), then add the missing call to camelize. --- lib/graphql/schema/input_object.rb | 4 ++-- spec/graphql/schema/input_object_spec.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/graphql/schema/input_object.rb b/lib/graphql/schema/input_object.rb index ca0e3ee56e..adfbe70822 100644 --- a/lib/graphql/schema/input_object.rb +++ b/lib/graphql/schema/input_object.rb @@ -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 = {} diff --git a/spec/graphql/schema/input_object_spec.rb b/spec/graphql/schema/input_object_spec.rb index 35eec220f1..cabb79d50e 100644 --- a/spec/graphql/schema/input_object_spec.rb +++ b/spec/graphql/schema/input_object_spec.rb @@ -493,18 +493,18 @@ def self.resolve_type(type, obj, ctx) it "introspects in GraphQL language with enums" do class InputDefaultSchema < GraphQL::Schema class Letter < GraphQL::Schema::Enum - value "A" - value "B" + value "A", value: 1 + value "B", value: 2 end class InputObj < GraphQL::Schema::InputObject - argument :a, Letter, required: false - argument :b, Letter, required: false + argument :arg_a, Letter, required: false + argument :arg_b, Letter, required: false end class Query < GraphQL::Schema::Object field :i, Int, null: true do - argument :arg, InputObj, required: false, default_value: { a: "A", b: "B" } + argument :arg, InputObj, required: false, default_value: { arg_a: 1, arg_b: 2 } end end @@ -524,7 +524,7 @@ class Query < GraphQL::Schema::Object } } " - assert_equal "{a: A, b: B}", res["data"]["__type"]["fields"].first["args"].first["defaultValue"] + assert_equal "{argA: A, argB: B}", res["data"]["__type"]["fields"].first["args"].first["defaultValue"] end end