From 1a18b55d77c65883c68970588c3bd9528c33865a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Wed, 12 Oct 2016 11:58:12 -0400 Subject: [PATCH] Use JSON's generate+quirks_mode to allow dumping scalar values --- lib/graphql/enum_type.rb | 2 +- lib/graphql/introspection/input_value_type.rb | 2 +- lib/graphql/scalar_type.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/graphql/enum_type.rb b/lib/graphql/enum_type.rb index 38419775ca..56bd168d08 100644 --- a/lib/graphql/enum_type.rb +++ b/lib/graphql/enum_type.rb @@ -91,7 +91,7 @@ def validate_non_null_input(value_name) result = GraphQL::Query::InputValidationResult.new if !@values_by_name.key?(value_name) - result.add_problem("Expected #{JSON.dump(value_name)} to be one of: #{@values_by_name.keys.join(', ')}") + result.add_problem("Expected #{JSON.generate(value_name, quirks_mode: true)} to be one of: #{@values_by_name.keys.join(', ')}") end result diff --git a/lib/graphql/introspection/input_value_type.rb b/lib/graphql/introspection/input_value_type.rb index b0ab40d6ac..d0e535d7e0 100644 --- a/lib/graphql/introspection/input_value_type.rb +++ b/lib/graphql/introspection/input_value_type.rb @@ -9,7 +9,7 @@ field :defaultValue, types.String, "A GraphQL-formatted string representing the default value for this input value." do resolve -> (obj, args, ctx) { value = obj.default_value - value.nil? ? nil : JSON.dump(obj.type.coerce_result(value)) + value.nil? ? nil : JSON.generate(obj.type.coerce_result(value), quirks_mode: true) } end end diff --git a/lib/graphql/scalar_type.rb b/lib/graphql/scalar_type.rb index 4c77750799..f5d8b420c3 100644 --- a/lib/graphql/scalar_type.rb +++ b/lib/graphql/scalar_type.rb @@ -44,7 +44,7 @@ def coerce=(proc) def validate_non_null_input(value) result = Query::InputValidationResult.new if coerce_non_null_input(value).nil? - result.add_problem("Could not coerce value #{JSON.dump(value)} to #{name}") + result.add_problem("Could not coerce value #{JSON.generate(value, quirks_mode: true)} to #{name}") end result end