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.
147 148 149 150 151 152 153 154 155 |
# File 'lib/graphql/schema.rb', line 147 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 with lazy_resolve
- After resolving value
, if it’s registered with lazy_resolve
(eg, Promise
)
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/graphql/schema.rb', line 107 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.
139 140 141 |
# File 'lib/graphql/schema.rb', line 139 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.
134 135 136 |
# File 'lib/graphql/schema.rb', line 134 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.
123 124 125 126 127 128 129 130 131 |
# File 'lib/graphql/schema.rb', line 123 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 |