Class: GraphQL::Execution::Lazy::LazyMethodMap

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/execution/lazy/lazy_method_map.rb

Overview

Schema uses this to match returned values to lazy resolution methods. Methods may be registered for classes, they apply to its subclasses also. The result of this lookup is cached for future resolutions.

Instance Method Summary collapse

Constructor Details

#initializeLazyMethodMap

Returns a new instance of LazyMethodMap.



9
10
11
12
13
14
15
16
17
18
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 9

def initialize
  @storage = Hash.new do |h, value_class|
    registered_superclass = h.each_key.find { |lazy_class| value_class < lazy_class }
    if registered_superclass.nil?
      h[value_class] = nil
    else
      h[value_class] = h[registered_superclass]
    end
  end
end

Instance Method Details

#eachObject



32
33
34
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 32

def each
  @storage.each { |k, v| yield(k,v) }
end

#get(value) ⇒ Symbol?

Returns The lazy_value_method for this object, or nil.

Parameters:

  • value (Object)

    an object which may have a lazy_value_method registered for its class or superclasses

Returns:

  • (Symbol, nil)

    The lazy_value_method for this object, or nil



28
29
30
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 28

def get(value)
  @storage[value.class]
end

#set(lazy_class, lazy_value_method) ⇒ Object

Parameters:

  • lazy_class (Class)

    A class which represents a lazy value (subclasses may also be used)

  • lazy_value_method (Symbol)

    The method to call on this class to get its value



22
23
24
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 22

def set(lazy_class, lazy_value_method)
  @storage[lazy_class] = lazy_value_method
end