class GraphQL::Execution::Lazy
This wraps a value which is available, but not yet calculated, like a promise or future.
Calling `#value` will trigger calculation & return the “lazy” value.
This is an itty-bitty promise-like object, with key differences:
-
It has only two states, not-resolved and resolved
-
It has no error-catching functionality
@api private
Constants
- NullResult
This can be used for fields which _had no_ lazy results @api private
Public Class Methods
@param lazies [Array<Object>] Maybe-lazy objects @return [Lazy] A lazy which will sync all of `lazies`
# File lib/graphql/execution/lazy.rb, line 60 def self.all(lazies) self.new { lazies.map { |l| l.is_a?(Lazy) ? l.value : l } } end
Create a {Lazy} which will get its inner value by calling the block @param get_value_func [Proc] a block to get the inner value (later)
# File lib/graphql/execution/lazy.rb, line 24 def initialize(&get_value_func) @get_value_func = get_value_func @resolved = false end
Traverse `val`, lazily resolving any values along the way @param val [Object] A data structure containing mixed plain values and `Lazy` instances @return void
# File lib/graphql/execution/lazy.rb, line 18 def self.resolve(val) Resolve.resolve(val) end
Public Instance Methods
@return [Lazy] A {Lazy} whose value depends on another {Lazy}, plus any transformations in `block`
# File lib/graphql/execution/lazy.rb, line 52 def then self.class.new { yield(value) } end
@return [Object] The wrapped value, calling the lazy block if necessary
# File lib/graphql/execution/lazy.rb, line 30 def value if !@resolved @resolved = true @value = begin v = @get_value_func.call if v.is_a?(Lazy) v = v.value end v rescue GraphQL::ExecutionError => err err end end if @value.is_a?(StandardError) raise @value else @value end end