Class: Ecoportal::API::GraphQL::Compat::Response
- Inherits:
-
Object
- Object
- Ecoportal::API::GraphQL::Compat::Response
- Defined in:
- lib/ecoportal/api/graphql/compat/response.rb
Overview
Wraps a GraphQL mutation payload to expose the v2-compatible response interface. Scripts check .success? and .status after update/create operations.
Constant Summary collapse
- PAYLOAD_CONTRACT =
The payload contract this wrapper delegates to. Guarded at construction so a payload of the wrong shape fails LOUD here, instead of silently downstream. This is the class of drift behind the eco-helpers 3.2.19 KPI-counter regression, where a Compat::Response (duck-typed, not a Common::Response) slipped through an
is_a?check and every GraphQL update went uncounted. %i[success? error? error_doc item].freeze
Instance Method Summary collapse
- #body ⇒ Object
- #error? ⇒ Boolean
-
#initialize(payload) ⇒ Response
constructor
A new instance of Response.
- #item ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(payload) ⇒ Response
Returns a new instance of Response.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ecoportal/api/graphql/compat/response.rb', line 15 def initialize(payload) missing = PAYLOAD_CONTRACT.reject { |meth| payload.respond_to?(meth) } unless missing.empty? raise ArgumentError, "Compat::Response payload #{payload.class} does not honour the expected " \ "response contract; missing: #{missing.join(', ')}" end @payload = payload end |
Instance Method Details
#body ⇒ Object
38 39 40 |
# File 'lib/ecoportal/api/graphql/compat/response.rb', line 38 def body @payload.error_doc end |
#error? ⇒ Boolean
30 31 32 |
# File 'lib/ecoportal/api/graphql/compat/response.rb', line 30 def error? @payload.error? end |
#item ⇒ Object
42 43 44 |
# File 'lib/ecoportal/api/graphql/compat/response.rb', line 42 def item @payload.item end |
#status ⇒ Object
34 35 36 |
# File 'lib/ecoportal/api/graphql/compat/response.rb', line 34 def status @payload.error? ? :error : :ok end |
#success? ⇒ Boolean
26 27 28 |
# File 'lib/ecoportal/api/graphql/compat/response.rb', line 26 def success? @payload.success? end |