Module: GraphQL::Schema::LazyHandlingMethods
- Included in:
- GraphQL::Schema, GraphQL::Schema
- Defined in:
- lib/graphql/schema.rb
Instance Method Summary collapse
-
#after_any_lazies(maybe_lazies) ⇒ Object
private
Return a lazy if any of
maybe_lazies
are lazy, otherwise, call the block eagerly and return the result. -
#after_lazy(value, &block) ⇒ Object
private
Call the given block at the right time, either: - Right away, if
value
is not registered withlazy_resolve
- After resolvingvalue
, if it's registered withlazy_resolve
(eg,Promise
). -
#lazy?(obj) ⇒ Boolean
True if this object should be lazily resolved.
-
#lazy_method_name(obj) ⇒ Symbol?
The method name to lazily resolve
obj
, or nil ifobj
's class wasn't registered with #lazy_resolve. -
#sync_lazy(value) ⇒ Object
private
Override this method to handle lazy objects in a custom way.
Instance Method Details
#after_any_lazies(maybe_lazies) ⇒ 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.
Return a lazy if any of maybe_lazies
are lazy,
otherwise, call the block eagerly and return the result.
150 151 152 153 154 155 156 157 158 |
# File 'lib/graphql/schema.rb', line 150 def after_any_lazies(maybe_lazies) if maybe_lazies.any? { |l| lazy?(l) } GraphQL::Execution::Lazy.all(maybe_lazies).then do |result| yield result end else yield maybe_lazies end end |
#after_lazy(value, &block) ⇒ 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.
Call the given block at the right time, either:
- Right away, if
value
is not registered withlazy_resolve
- After resolving
value
, if it's registered withlazy_resolve
(eg,Promise
)
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/graphql/schema.rb', line 110 def after_lazy(value, &block) if lazy?(value) GraphQL::Execution::Lazy.new do result = sync_lazy(value) # The returned result might also be lazy, so check it, too after_lazy(result, &block) end else yield(value) if block_given? end end |
#lazy?(obj) ⇒ Boolean
Returns True if this object should be lazily resolved.
142 143 144 |
# File 'lib/graphql/schema.rb', line 142 def lazy?(obj) !!lazy_method_name(obj) end |
#lazy_method_name(obj) ⇒ Symbol?
Returns The method name to lazily resolve obj
, or nil if obj
's class wasn't registered with #lazy_resolve.
137 138 139 |
# File 'lib/graphql/schema.rb', line 137 def lazy_method_name(obj) lazy_methods.get(obj) end |
#sync_lazy(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.
Override this method to handle lazy objects in a custom way.
126 127 128 129 130 131 132 133 134 |
# File 'lib/graphql/schema.rb', line 126 def sync_lazy(value) lazy_method = lazy_method_name(value) if lazy_method synced_value = value.public_send(lazy_method) sync_lazy(synced_value) else value end end |