Implement DataLoader as an @Injectable({ scope: Scope.REQUEST }) service. Scope.REQUEST is critical — DataLoader caches keys for the lifetime of the request and a singleton loader would serve stale data across requests. The batch function receives an array of keys and must return results in the same order.
Scope.REQUEST — a new DataLoader instance per request; prevents cross-request cache contamination.
Singleton DataLoader would serve cached data from previous requests to different users — a security issue.
The batch function must return results in exactly the same order as the input keys array.
Return null for missing keys — DataLoader expects the array length to match the keys length.
cache: true (default) deduplicates repeated loads of the same key within one request.