Skip to content

Commit 1673f69

Browse files
committed
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.
1 parent 173ad1b commit 1673f69

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

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

spec/graphql/schema/input_object_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,18 +493,18 @@ def self.resolve_type(type, obj, ctx)
493493
it "introspects in GraphQL language with enums" do
494494
class InputDefaultSchema < GraphQL::Schema
495495
class Letter < GraphQL::Schema::Enum
496-
value "A"
497-
value "B"
496+
value "A", value: 1
497+
value "B", value: 2
498498
end
499499

500500
class InputObj < GraphQL::Schema::InputObject
501-
argument :a, Letter, required: false
502-
argument :b, Letter, required: false
501+
argument :arg_a, Letter, required: false
502+
argument :arg_b, Letter, required: false
503503
end
504504

505505
class Query < GraphQL::Schema::Object
506506
field :i, Int, null: true do
507-
argument :arg, InputObj, required: false, default_value: { a: "A", b: "B" }
507+
argument :arg, InputObj, required: false, default_value: { arg_a: 1, arg_b: 2 }
508508
end
509509
end
510510

@@ -524,7 +524,7 @@ class Query < GraphQL::Schema::Object
524524
}
525525
}
526526
"
527-
assert_equal "{a: A, b: B}", res["data"]["__type"]["fields"].first["args"].first["defaultValue"]
527+
assert_equal "{argA: A, argB: B}", res["data"]["__type"]["fields"].first["args"].first["defaultValue"]
528528
end
529529
end
530530

0 commit comments

Comments
 (0)