NestJS · Senior · Question 39 of 75
Why must DataLoader instances be created per request in a Nest GraphQL app?
- 1DataLoader can be created only once per process
- 2Per-request loaders are slower but required by GraphQL
- ✓Correct answer: DataLoader caches results; sharing it across requests leaks data between users and serves stale values
Explanation
Create loaders in the GraphQL context factory or a request-scoped provider.