# graphql/dataloader architecture

> Architecture diagram of the GitHub repository graphql/dataloader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/graphql/dataloader
- Repository: https://github.com/graphql/dataloader

## Overview

DataLoader is a small JavaScript utility that coalesces individual key requests into scheduled batches for an application-provided loader function, while memoizing loads per instance. Its principal flow is caller → DataLoader → batch function → remote data source; cache hits avoid duplicate keys. The README documents configurable scheduling and cache behavior. The source excerpt shows queueing and cache operations, but omits the full dispatch implementation, so dispatch relationships rely on README documentation.

Main entry points: [`src/index.js`](https://github.com/graphql/dataloader/blob/main/src/index.js) (DataLoader API)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_caller(("Application caller"))
node_api["DataLoader API<br/>[index.js]"]
node_batching["Batch dispatch<br/>[index.js]"]
node_batch_fn["Batch function"]
node_backend[("Backend service")]
node_cache[("Instance cache<br/>[index.js]")]
node_scheduler["Custom scheduler"]

node_caller -->|"loads keys"| node_api
node_api -->|"checks memoization"| node_cache
node_api -->|"queues keys"| node_batching
node_batching -->|"dispatches batch"| node_batch_fn
node_batch_fn -->|"fetches data"| node_backend
node_api -.->|"configures scheduling"| node_scheduler

click node_api "https://github.com/graphql/dataloader/blob/main/src/index.js"
click node_batching "https://github.com/graphql/dataloader/blob/main/src/index.js"
click node_cache "https://github.com/graphql/dataloader/blob/main/src/index.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_caller,node_batch_fn toneIndigo
class node_api toneMint
class node_batching toneTeal
class node_backend,node_cache toneAmber
class node_scheduler toneRose
```

## Components

### Other components

- **Application caller**
- [DataLoader API](https://github.com/graphql/dataloader/blob/main/src/index.js): `src/index.js`
- [Batch dispatch](https://github.com/graphql/dataloader/blob/main/src/index.js): `src/index.js`
- **Batch function**
- **Backend service**
- [Instance cache](https://github.com/graphql/dataloader/blob/main/src/index.js): `src/index.js`
- **Custom scheduler**

## Connections

- Application caller → DataLoader API: loads keys (evidence: `README.md`)
- DataLoader API → Instance cache: checks memoization (evidence: `src/index.js`)
- DataLoader API → Batch dispatch: queues keys (evidence: `src/index.js`)
- Batch dispatch → Batch function: dispatches batch (evidence: `README.md`)
- Batch function → Backend service: fetches data (evidence: `README.md`)
- DataLoader API → Custom scheduler: configures scheduling (evidence: `README.md`)
