Class: GraphQL::Execution::Lazy Private
- Inherits:
-
Object
- Object
- GraphQL::Execution::Lazy
- Defined in:
- lib/graphql/execution/lazy.rb,
lib/graphql/execution/lazy/lazy_method_map.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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
Defined Under Namespace
Classes: LazyMethodMap
Constant Summary collapse
- NullResult =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
This can be used for fields which had no lazy results
Lazy.new(){}
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
private
-
#path ⇒ Object
readonly
private
Class Method Summary collapse
-
.all(lazies) ⇒ Lazy
private
A lazy which will sync all of
lazies
. -
.resolve(val) ⇒ Object
private
Traverse
val
, lazily resolving any values along the way.
Instance Method Summary collapse
-
#initialize(path: nil, field: nil, &get_value_func) ⇒ Lazy
constructor
private
Create a Lazy which will get its inner value by calling the block.
- #then ⇒ Lazy private
-
#value ⇒ Object
private
The wrapped value, calling the lazy block if necessary.
Constructor Details
#initialize(path: nil, field: nil, &get_value_func) ⇒ Lazy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a GraphQL::Execution::Lazy which will get its inner value by calling the block
28 29 30 31 32 33 |
# File 'lib/graphql/execution/lazy.rb', line 28 def initialize(path: nil, field: nil, &get_value_func) @get_value_func = get_value_func @resolved = false @path = path @field = field end |
Instance Attribute Details
#field ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 |
# File 'lib/graphql/execution/lazy.rb', line 22 def field @field end |
#path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 |
# File 'lib/graphql/execution/lazy.rb', line 22 def path @path end |
Class Method Details
.all(lazies) ⇒ Lazy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns A lazy which will sync all of lazies
.
70 71 72 73 74 |
# File 'lib/graphql/execution/lazy.rb', line 70 def self.all(lazies) self.new { lazies.map { |l| l.is_a?(Lazy) ? l.value : l } } end |
.resolve(val) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Traverse val
, lazily resolving any values along the way
18 19 20 |
# File 'lib/graphql/execution/lazy.rb', line 18 def self.resolve(val) Resolve.resolve(val) end |
Instance Method Details
#then ⇒ Lazy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns A GraphQL::Execution::Lazy whose value depends on another GraphQL::Execution::Lazy, plus any transformations in block
.
62 63 64 65 66 |
# File 'lib/graphql/execution/lazy.rb', line 62 def then self.class.new { yield(value) } end |
#value ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The wrapped value, calling the lazy block if necessary.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/graphql/execution/lazy.rb', line 36 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 # `SKIP` was made into a subclass of `GraphQL::Error` to improve runtime performance # (fewer clauses in a hot `case` block), but now it requires special handling here. # I think it's still worth it for the performance win, but if the number of special # cases grows, then maybe it's worth rethinking somehow. if @value.is_a?(StandardError) && @value != GraphQL::Execution::SKIP raise @value else @value end end |