DataLoadermedium3-5 years

Walk through what actually changes when a resolver moves from `@SchemaMapping` (per-object) to `@BatchMapping` (per-level). Does the engine call the new method less often in the same way it would call a cached method less often?

Not in the sense of a cache — a cache would still be hit twenty times, just cheaply. @BatchMapping changes what the resolver is: instead of a method that takes one Order and returns one Customer, it's a method that takes the whole list of Orders from that level and returns a map from each one to its Customer. The engine doesn't call it once per order; as it walks the twenty orders resolving customer on each, it defers every one of those instead of resolving them immediately, collects all twenty keys, and once the whole level is done being walked, dispatches the batch method exactly once with all twenty keys at once. One WHERE id IN (...) replaces twenty separate lookups — not a faster twenty calls, one call.

The lesson behind it →
More on DataLoader