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.10.0.pre4 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.18 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.10.0.pre3 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.17 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.10.0.pre2 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.16 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.15 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.14 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.10.0.pre1 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.13 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.12 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.11 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.10 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.9 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.8 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.7 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.6 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.5 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.4 lib/graphql/execution/interpreter/hash_response.rb
graphql-1.9.3 lib/graphql/execution/interpreter/hash_response.rb