From de75b8e3f37571d6073d5b38cef383cb59b7d6ee Mon Sep 17 00:00:00 2001 From: Alexandru Prian Date: Thu, 8 Sep 2022 09:38:08 +0200 Subject: [PATCH] add to_hash alias to to_h method of ObjectType and Response --- lib/graphql/client/response.rb | 1 + lib/graphql/client/schema/object_type.rb | 1 + test/test_query_result.rb | 1 + 3 files changed, 3 insertions(+) diff --git a/lib/graphql/client/response.rb b/lib/graphql/client/response.rb index cc8dc620..f2624180 100644 --- a/lib/graphql/client/response.rb +++ b/lib/graphql/client/response.rb @@ -12,6 +12,7 @@ class Response # Returns Hash. attr_reader :original_hash alias_method :to_h, :original_hash + alias_method :to_hash, :original_hash # Public: Wrapped ObjectType of data returned from the server. # diff --git a/lib/graphql/client/schema/object_type.rb b/lib/graphql/client/schema/object_type.rb index e1cccf30..4233f195 100644 --- a/lib/graphql/client/schema/object_type.rb +++ b/lib/graphql/client/schema/object_type.rb @@ -192,6 +192,7 @@ def initialize(data = {}, errors = Errors.new, definer = nil) def to_h @data end + alias :to_hash :to_h def _definer @definer diff --git a/test/test_query_result.rb b/test/test_query_result.rb index ffc6fa3c..ed6cd83e 100644 --- a/test/test_query_result.rb +++ b/test/test_query_result.rb @@ -272,6 +272,7 @@ def test_snakecase_field_aliases person = Temp::Person.new(@client.query(Temp::Query).data.me) raw_result = {"firstName"=>"Joshua", "lastName"=>"Peek"} assert_equal raw_result, person.to_h + assert_equal raw_result, person.to_hash assert_equal "Joshua", person.first_name assert_equal "Peek", person.last_name