Non-Blocking Data Loading for GraphQL

You can pass nonblocking: true to enable a non-blocking dataloader implementation based on Ruby 3’s Fiber.scheduler API:

class MySchema < GraphQL::Schema
  use GraphQL::Dataloader, nonblocking: true # enable parallel data loading
end

Alternatively, you can add a non-blocking GraphQL::Dataloader instance to context[:dataloader]:

context = {
  # ...
  dataloader: GraphQL::Dataloader.new(nonblocking: true),
}
MySchema.execute(query_string, context: context, ...)

Additionally, you must set up a Fiber scheduler with Fiber.set_scheduler before running your query:

Fiber.set_scheduler(MySchedulerImplementation.new)
MySchema.execute(...)

The scheduler must implement Fiber::SchedulerImplementation. Some implementations are available off-the-shelf: