Sha256: c4d09daa83033f44af237e60bd53980d0ad1483a2075bd1e964dc06eb738a021

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module GraphQL
  module Execution
    class Interpreter
      # This response class handles `#write` by accumulating
      # values into a Hash.
      class HashResponse
        def initialize
          @result = {}
        end

        def final_value
          @result
        end

        def inspect
          "#<#{self.class.name} result=#{@result.inspect}>"
        end

        # Add `value` at `path`.
        # @return [void]
        def write(path, value)
          if path.size == 0 # faster than #none?
            @result = value
          elsif (write_target = @result)
            i = 0
            prefinal_steps = path.size - 1
            # Use `while` to avoid a closure
            while i < prefinal_steps
              path_part = path[i]
              i += 1
              write_target = write_target[path_part]
            end
            path_part = path[i]
            write_target[path_part] = value
          else
            # The response is completely nulled out
          end

          nil
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
graphql-1.9.0.pre3 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.0.pre2 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.0.pre1 lib/graphql/execution/interpreter/hash_response.rb