class GraphQL::Execution::Interpreter::Runtime::GraphQLResultHash

Attributes

graphql_merged_into[RW]

Public Class Methods

new(_result_name, _parent_result) click to toggle source
# File lib/graphql/execution/interpreter/runtime.rb, line 39
def initialize(_result_name, _parent_result)
  super
  @graphql_result_data = {}
end

Public Instance Methods

[](k) click to toggle source
# File lib/graphql/execution/interpreter/runtime.rb, line 92
def [](k)
  (@graphql_metadata || @graphql_result_data)[k]
end
[]=(key, value) click to toggle source
# File lib/graphql/execution/interpreter/runtime.rb, line 48
def []=(key, value)
  # This is a hack.
  # Basically, this object is merged into the root-level result at some point.
  # But the problem is, some lazies are created whose closures retain reference to _this_
  # object. When those lazies are resolved, they cause an update to this object.
  #
  # In order to return a proper top-level result, we have to update that top-level result object.
  # In order to return a proper partial result (eg, for a directive), we have to update this object, too.
  # Yowza.
  if (t = @graphql_merged_into)
    t[key] = value
  end

  if value.respond_to?(:graphql_result_data)
    @graphql_result_data[key] = value.graphql_result_data
    # If we encounter some part of this response that requires metadata tracking,
    # then create the metadata hash if necessary. It will be kept up-to-date after this.
    (@graphql_metadata ||= @graphql_result_data.dup)[key] = value
  else
    @graphql_result_data[key] = value
    # keep this up-to-date if it's been initialized
    @graphql_metadata && @graphql_metadata[key] = value
  end

  value
end
delete(key) click to toggle source
# File lib/graphql/execution/interpreter/runtime.rb, line 75
def delete(key)
  @graphql_metadata && @graphql_metadata.delete(key)
  @graphql_result_data.delete(key)
end
each() { |k, v| ... } click to toggle source
# File lib/graphql/execution/interpreter/runtime.rb, line 80
def each
  (@graphql_metadata || @graphql_result_data).each { |k, v| yield(k, v) }
end
key?(k) click to toggle source
# File lib/graphql/execution/interpreter/runtime.rb, line 88
def key?(k)
  @graphql_result_data.key?(k)
end
values() click to toggle source
# File lib/graphql/execution/interpreter/runtime.rb, line 84
def values
  (@graphql_metadata || @graphql_result_data).values
end