Sha256: 1e2aa0882dfa78c4d74e47050606fef17b2c0f5210c9ec2f597bb8d695a26eac

Contents?: true

Size: 1.04 KB

Versions: 64

Compression:

Stored size: 1.04 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.empty?
            @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

64 entries across 64 versions & 1 rubygems

Version Path
graphql-1.11.10 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.11.9 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.12.10 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.12.9 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.12.8 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.12.7 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.12.6 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.12.5 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.11.8 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.12.4 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.12.3 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.12.2 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.12.1 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.12.0 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.11.7 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.11.6 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.11.5 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.11.4 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.11.3 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.11.2 lib/graphql/execution/interpreter/hash_response.rb