Skip to content

Commit

Permalink
add to_hash alias to to_h method of ObjectType and Response
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru Prian authored and ElvinEfendi committed Feb 21, 2024
1 parent bec141a commit de75b8e
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 de75b8e

Please sign in to comment.