Class: SimpleGraphqlClient::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_graphql_client/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Response

Returns a new instance of Response.



10
11
12
# File 'lib/simple_graphql_client/response.rb', line 10

def initialize(raw_response)
  @raw_response = raw_response
end

Instance Attribute Details

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



8
9
10
# File 'lib/simple_graphql_client/response.rb', line 8

def raw_response
  @raw_response
end

Instance Method Details

#bodyObject



14
15
16
17
18
19
20
21
# File 'lib/simple_graphql_client/response.rb', line 14

def body
  parsed_body = Hashie::Mash.new(JSON.parse(raw_response.body))
  raise SimpleGraphqlClient::Errors::QueryError, parsed_body.errors if parsed_body.errors

  parsed_body.data
rescue JSON::ParserError => e
  raise SimpleGraphqlClient::Errors::ParserError.new(e, raw_response)
end

#errorsObject



23
24
25
# File 'lib/simple_graphql_client/response.rb', line 23

def errors
  response_body
end