Class: ActiveGraphql::Client::Response
- Inherits:
-
Object
- Object
- ActiveGraphql::Client::Response
- Defined in:
- lib/active_graphql/client/response.rb
Overview
graphql response wrapper
Instance Attribute Summary collapse
-
#graphql_object ⇒ Object
readonly
Returns the value of attribute graphql_object.
Instance Method Summary collapse
- #detailed_errors ⇒ Object
- #errors ⇒ Object
-
#initialize(graphql_object, error = nil) ⇒ Response
constructor
A new instance of Response.
- #result ⇒ Object
- #result! ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(graphql_object, error = nil) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 14 15 16 |
# File 'lib/active_graphql/client/response.rb', line 9 def initialize(graphql_object, error = nil) if graphql_object root_field = graphql_object.to_h.keys.first.to_s.underscore @graphql_object = graphql_object.public_send(root_field) end @graphql_error = error if error end |
Instance Attribute Details
#graphql_object ⇒ Object (readonly)
Returns the value of attribute graphql_object.
7 8 9 |
# File 'lib/active_graphql/client/response.rb', line 7 def graphql_object @graphql_object end |
Instance Method Details
#detailed_errors ⇒ Object
32 33 34 35 36 |
# File 'lib/active_graphql/client/response.rb', line 32 def detailed_errors return [] if graphql_error.blank? graphql_error.errors.details['data'].map(&:with_indifferent_access) end |
#errors ⇒ Object
38 39 40 |
# File 'lib/active_graphql/client/response.rb', line 38 def errors detailed_errors.map { |error| error[:message] } end |
#result ⇒ Object
18 19 20 |
# File 'lib/active_graphql/client/response.rb', line 18 def result graphql_object end |
#result! ⇒ Object
22 23 24 25 26 |
# File 'lib/active_graphql/client/response.rb', line 22 def result! raise ActiveGraphql::Errors::ResponseError, errors.first if errors.any? graphql_object end |
#success? ⇒ Boolean
28 29 30 |
# File 'lib/active_graphql/client/response.rb', line 28 def success? graphql_error.nil? end |