Module: GraphQL::Execution::Interpreter::Resolve
- Defined in:
- lib/graphql/execution/interpreter/resolve.rb
Class Method Summary collapse
-
.resolve(results, dataloader) ⇒ Object
Deprecated: Call
dataloader.runinstead : (Array results, GraphQL::Dataloader dataloader) -> nil. -
.resolve_all(results, dataloader) ⇒ Object
Continue field results in
resultsuntil there's nothing else to continue. -
.resolve_each_depth(lazies_at_depth, dataloader) ⇒ Object
Deprecated: Call
dataloader.runinstead : (Hash[Integer, Array[GraphQL::Execution::Lazy]] lazies_at_depth, GraphQL::Dataloader dataloader) -> nil.
Class Method Details
.resolve(results, dataloader) ⇒ Object
Deprecated: Call dataloader.run instead
: (Array results, GraphQL::Dataloader dataloader) -> nil
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/graphql/execution/interpreter/resolve.rb', line 56 def self.resolve(results, dataloader) backtrace = caller(1, 5) #: as !nil warn "#{self}.#{__method__} is deprecated; Use `dataloader.run` instead.#{backtrace.map { |l| "\n #{l}"}.join}" # There might be pending jobs here that _will_ write lazies # into the result hash. We should run them out, so we # can be sure that all lazies will be present in the result hashes. # A better implementation would somehow interleave (or unify) # these approaches. dataloader.run next_results = [] while !results.empty? result_value = results.shift if result_value.is_a?(Runtime::GraphQLResultHash) || result_value.is_a?(Hash) results.concat(result_value.values) next elsif result_value.is_a?(Runtime::GraphQLResultArray) results.concat(result_value.values) next elsif result_value.is_a?(Array) results.concat(result_value) next elsif result_value.is_a?(Lazy) loaded_value = result_value.value if loaded_value.is_a?(Lazy) # Since this field returned another lazy, # add it to the same queue results << loaded_value elsif loaded_value.is_a?(Runtime::GraphQLResultHash) || loaded_value.is_a?(Runtime::GraphQLResultArray) || loaded_value.is_a?(Hash) || loaded_value.is_a?(Array) # Add these values in wholesale -- # they might be modified by later work in the dataloader. next_results << loaded_value end end end if !next_results.empty? # Any pending data loader jobs may populate the # resutl arrays or result hashes accumulated in # `next_results``. Run those **to completion** # before continuing to resolve `next_results`. # (Just `.append_job` doesn't work if any pending # jobs require multiple passes.) dataloader.run dataloader.append_job { resolve(next_results, dataloader) } end nil end |
.resolve_all(results, dataloader) ⇒ Object
Continue field results in results until there's nothing else to continue.
Deprecated: Call dataloader.run instead
Returns
void
:call-seq:
resolve_all(results, dataloader) -> void
: (Array results, GraphQL::Dataloader dataloader) -> nil
19 20 21 22 23 24 |
# File 'lib/graphql/execution/interpreter/resolve.rb', line 19 def self.resolve_all(results, dataloader) backtrace = caller(1, 5) #: as !nil warn "#{self}.#{__method__} is deprecated; Use `dataloader.run` instead.#{backtrace.map { |l| "\n #{l}"}.join}" dataloader.append_job { resolve(results, dataloader) } nil end |
.resolve_each_depth(lazies_at_depth, dataloader) ⇒ Object
Deprecated: Call dataloader.run instead
: (Hash[Integer, Array[GraphQL::Execution::Lazy]] lazies_at_depth, GraphQL::Dataloader dataloader) -> nil
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/graphql/execution/interpreter/resolve.rb', line 28 def self.resolve_each_depth(lazies_at_depth, dataloader) backtrace = caller(1, 5) #: as !nil warn "#{self}.#{__method__} is deprecated; Use `dataloader.run` instead.#{backtrace.map { |l| "\n #{l}"}.join}" smallest_depth = nil #: Integer? lazies_at_depth.each_key do |depth_key| smallest_depth ||= depth_key if depth_key < smallest_depth smallest_depth = depth_key end end if smallest_depth lazies = lazies_at_depth.delete(smallest_depth) #: as !nil if !lazies.empty? lazies.each do |l| dataloader.append_job { l.value } end # Run lazies _and_ dataloader, see if more are enqueued dataloader.run resolve_each_depth(lazies_at_depth, dataloader) end end nil end |