Skip to main content

createDataloaders

API Docs


Function: createDataloaders()

createDataloaders(db, cache, perf?): Dataloaders

Defined in: src/utilities/dataloaders/index.ts:53

Creates all DataLoaders for a request context. Each loader is request-scoped to ensure proper caching and isolation. When a cache service is provided, DataLoaders use cache-first lookup strategy. When a performance tracker is provided, DataLoaders track database operation durations.

Parameters

db

DrizzleClient

The Drizzle client instance for database operations.

cache

Optional cache service for cache-first lookups. Pass null to disable caching.

CacheService | null

perf?

PerformanceTracker

Optional performance tracker for monitoring database operation durations.

Returns

Dataloaders

An object containing all DataLoaders.

Example

const dataloaders = createDataloaders(drizzleClient, cacheService, perfTracker);
const user = await dataloaders.user.load(userId);
const organization = await dataloaders.organization.load(orgId);