Sha256: 57f58561294801517ece2a34bf6bdce20edddf832aa13415cd1d2240ebe8d065

Contents?: true

Size: 784 Bytes

Versions: 1

Compression:

Stored size: 784 Bytes

Contents

module StoryBranch
  module Graphql
    # Model to handle graphql response and make it more friendly. Detect if errors
    # are present in the reponse and marks the response as failed if so
    # gives a few accessors to data
    class Response
      def initialize(response:)
        @response = response
      end

      def data
        @data ||= @response.parsed_response["data"]
      end

      def success?
        errors.nil? && @response.success?
      end

      def errors
        return @errors if @errors

        @errors = if @response.success?
          @response.parsed_response["errors"]
        else
          [@response.response, @response.parsed_response]
        end
      end

      def full_error_messages
        errors.join("\n")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
story_branch-graphql-0.0.2 lib/story_branch/graphql/response.rb