module GraphQL::Schema::LazyHandlingMethods
Public Instance Methods
after_any_lazies(maybe_lazies) { |result| ... }
click to toggle source
Return a lazy if any of `maybe_lazies` are lazy, otherwise, call the block eagerly and return the result. @param maybe_lazies [Array] @api private
# 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) { |value| ... }
click to toggle source
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`)
@api private
# 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)
click to toggle source
@return [Boolean] True if this object should be lazily resolved
# File lib/graphql/schema.rb, line 142 def lazy?(obj) !!lazy_method_name(obj) end
lazy_method_name(obj)
click to toggle source
@return [Symbol, nil] The method name to lazily resolve `obj`, or nil if `obj`'s class wasn't registered with {#lazy_resolve}.
# File lib/graphql/schema.rb, line 137 def lazy_method_name(obj) lazy_methods.get(obj) end
sync_lazy(value)
click to toggle source
Override this method to handle lazy objects in a custom way. @param value [Object] an instance of a class registered with {.lazy_resolve} @return [Object] A GraphQL-ready (non-lazy) object @api private
# 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