Optimize a GraphQL resolver
Fix N+1 query problems in a GraphQL resolver using DataLoader for batched, cached DB calls. Includes a before/after DB query count comparison.
Preview
Copy prompt
The following GraphQL resolver causes an N+1 query problem, running one database query per parent list item: [Paste resolver code]. Fix it using DataLoader. Define the batch function that groups IDs into a single query and maps results back. Instantiate DataLoader per-request to prevent stale caching. Handle the one-to-many case correctly. Show a before-and-after comparison of query count for a list of 50 parent items.
More
Performance
Prompts
