Skip to content

Commit

Permalink
Merge pull request #16 from ElvinEfendi/to_hash-alias-to_h
Browse files Browse the repository at this point in the history
add to_hash alias to to_h method of ObjectType and Response
  • Loading branch information
rmosolgo authored Feb 21, 2024
2 parents bec141a + de75b8e commit ee19269
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/graphql/client/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
1 change: 1 addition & 0 deletions lib/graphql/client/schema/object_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/test_query_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ee19269

Please sign in to comment.