Class: GraphQL::Dataloader::NullDataloader
- Inherits:
-
Dataloader
- Object
- Dataloader
- GraphQL::Dataloader::NullDataloader
- Defined in:
- lib/graphql/dataloader/null_dataloader.rb
Overview
GraphQL-Ruby uses this when Dataloader isn't enabled.
It runs execution code inline and gathers lazy objects (eg. Promises) and resolves them during #run.
Instance Method Summary collapse
- #append_job(callable = nil) ⇒ Object
- #clear_cache ⇒ Object
- #freeze ⇒ Object
-
#initialize ⇒ NullDataloader
constructor
A new instance of NullDataloader.
- #run(trace_query_lazy: nil) ⇒ Object
- #run_isolated ⇒ Object
- #with ⇒ Object
- #yield(_source) ⇒ Object
Constructor Details
#initialize ⇒ NullDataloader
Returns a new instance of NullDataloader.
10 11 12 |
# File 'lib/graphql/dataloader/null_dataloader.rb', line 10 def initialize(*) @lazies_at_depth = Hash.new { |h,k| h[k] = [] } end |
Instance Method Details
#append_job(callable = nil) ⇒ Object
59 60 61 62 |
# File 'lib/graphql/dataloader/null_dataloader.rb', line 59 def append_job(callable = nil) callable ? callable.call : yield nil end |
#clear_cache ⇒ Object
53 |
# File 'lib/graphql/dataloader/null_dataloader.rb', line 53 def clear_cache; end |
#freeze ⇒ Object
14 15 16 17 18 |
# File 'lib/graphql/dataloader/null_dataloader.rb', line 14 def freeze @lazies_at_depth.default_proc = nil @lazies_at_depth.freeze super end |
#run(trace_query_lazy: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/graphql/dataloader/null_dataloader.rb', line 20 def run(trace_query_lazy: nil) with_trace_query_lazy(trace_query_lazy) do while !@lazies_at_depth.empty? smallest_depth = nil @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) lazies.each(&:value) # resolve these Lazy instances end end end end |
#run_isolated ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/graphql/dataloader/null_dataloader.rb', line 39 def run_isolated # Reuse this instance because execution code may already have a reference to _this_ `dataloader` inside the given block. prev_lazies_at_depth = @lazies_at_depth @lazies_at_depth = @lazies_at_depth.dup.clear res = nil append_job { res = yield } run res ensure @lazies_at_depth = prev_lazies_at_depth end |