Sha256: 531576f7ebba28e022773280ea4bfb3a1b6a0c0c82372488a3720648f1b8f696

Contents?: true

Size: 687 Bytes

Versions: 2

Compression:

Stored size: 687 Bytes

Contents

# frozen_string_literal: true

module GraphQL
  module Client
    class ResponseObject
      include Deserialization

      attr_reader :data

      def initialize(data)
        @data = Hash(data)

        @data.each do |field_name, value|
          response_object = case value
          when Hash
            if value.key?('edges')
              ResponseConnection.new(value)
            else
              self.class.new(value)
            end
          when Array
            value.map { |v| v.is_a?(Hash) ? self.class.new(v) : v }
          else
            value
          end

          create_accessor_methods(field_name, response_object)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphql_client-0.4.1 lib/graphql_client/response_object.rb
graphql_client-0.3.3 lib/graphql_client/response_object.rb