Dataloader vs. GraphQL-Batch

GraphQL::Dataloader solves the same problem as GraphQL::Batch. There are a few major differences between the modules:

The incentive in writing GraphQL::Dataloader was to leverage Fiber’s ability to transparently pause and resume work, which removes the need for Promises (and removes the resulting complexity in the code). Additionally, GraphQL::Dataloader should eventually support Ruby 3.0’s Fiber.scheduler API, which runs I/O in the background by default.

Comparison: Fetching a single object

In this example, a single object is batch-loaded to satisfy a GraphQL field.

Comparison: Fetching objects in sequence (dependent)

In this example, one object is loaded, then another object is loaded based on the first one.

Comparison: Fetching objects concurrently (independent)

Sometimes, you need multiple independent records to perform a calcuation. Each record is loaded, then they’re combined in some bit of work.