Skip to content

Commit de75b8e

Browse files
Alexandru PrianElvinEfendi
authored andcommitted
add to_hash alias to to_h method of ObjectType and Response
1 parent bec141a commit de75b8e

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

lib/graphql/client/response.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Response
1212
# Returns Hash.
1313
attr_reader :original_hash
1414
alias_method :to_h, :original_hash
15+
alias_method :to_hash, :original_hash
1516

1617
# Public: Wrapped ObjectType of data returned from the server.
1718
#

lib/graphql/client/schema/object_type.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def initialize(data = {}, errors = Errors.new, definer = nil)
192192
def to_h
193193
@data
194194
end
195+
alias :to_hash :to_h
195196

196197
def _definer
197198
@definer

test/test_query_result.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ def test_snakecase_field_aliases
272272
person = Temp::Person.new(@client.query(Temp::Query).data.me)
273273
raw_result = {"firstName"=>"Joshua", "lastName"=>"Peek"}
274274
assert_equal raw_result, person.to_h
275+
assert_equal raw_result, person.to_hash
275276

276277
assert_equal "Joshua", person.first_name
277278
assert_equal "Peek", person.last_name

0 commit comments

Comments
 (0)