Class: GraphQL::Dataloader::AsyncDataloader

Inherits:
Dataloader
  • Object
show all
Defined in:
lib/graphql/dataloader/async_dataloader.rb

Defined Under Namespace

Classes: Run

Instance Method Summary collapse

Instance Method Details

#run(trace_query_lazy: nil) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/graphql/dataloader/async_dataloader.rb', line 115

def run(trace_query_lazy: nil)
  trace = Fiber[:__graphql_current_multiplex]&.current_trace
  jobs_fiber_limit, total_fiber_limit = calculate_fiber_limit
  first_pass = true
  trace&.begin_dataloader(self)
  fiber_vars = get_fiber_variables
  raised_error = nil
  Sync do |root_task|
    run = Run.new(root_task, trace, total_fiber_limit, jobs_fiber_limit)
    set_fiber_variables(fiber_vars)

    while first_pass || run.running? || !@pending_jobs.empty?
      first_pass = false
      run_pending_steps(run)
      run_sources(run)

      if !@lazies_at_depth.empty?
        with_trace_query_lazy(trace_query_lazy) do
          run_next_pending_lazies(run)
          run_pending_steps(run)
        end
      end
    end
  rescue StandardError => err
    raised_error = err
    root_task.cancel
  end

  if raised_error
    raise raised_error
  end
  trace&.end_dataloader(self)
rescue UncaughtThrowError => e
  throw e.tag, e.value
end

#yield(source = Fiber[:__graphql_current_dataloader_source]) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/graphql/dataloader/async_dataloader.rb', line 6

def yield(source = Fiber[:__graphql_current_dataloader_source])
  run = Fiber[:__graphql_async_dataloader_run]
  trace = run.trace
  trace&.dataloader_fiber_yield(source)
  task = Async::Task.current
  run.finished_tasks.push(task)
  condition = Fiber[:__graphql_async_dataloader_condition]
  condition.wait
  run.started_tasks.push(task)
  trace&.dataloader_fiber_resume(source)
  nil
end