# GraphQLDependency.defineLoader() method · @imqueue/graphql-dependency

Source: https://imqueue.org/api/graphql-dependency/latest/graphql-dependency.graphqldependency.defineloader/
Published: 2026-07-31
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/graphql-dependency 3.1.0 — generated reference, not hand-written

Declares how to fetch many objects of this type in one call, which is what makes the type usable as another type's dependency.

**Signature:**

```typescript
defineLoader<T>(loader: DataLoader<T>): GraphQLDependency<ResultType>;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| loader | [DataLoader](https://imqueue.org/api/graphql-dependency/latest/graphql-dependency.dataloader/)<T> | bulk fetch for this type |


**Returns:**

[GraphQLDependency](https://imqueue.org/api/graphql-dependency/latest/graphql-dependency.graphqldependency/)<ResultType>

this description, so calls can be chained

## Remarks

The loader receives a filter assembled from the parent objects — its shape is whatever [GraphQLDependency.require()](https://imqueue.org/api/graphql-dependency/latest/graphql-dependency.graphqldependency.require/) maps into it — together with the merged set of fields the query asked for, so both can be pushed down to the service or store behind it.

Two things are required of it. Every object it returns must carry an `id`, because results are keyed by id and attached to parents by id. And it must accept a \*set\* of values per filter key rather than one, since fetching a whole level of parents in a single call is the entire point.

Declaring a loader is also what makes a type eligible to be `require()`d elsewhere. A type with requirements but no loader is not an error: no call is made for it, and its own children are still resolved against whatever data the parent result already holds.

## Example


```typescript
Dependency(UserType).defineLoader(async (
    context: any,
    filter: FiltersInput,
    fields?: FieldsMapInput,
) => (await context.user.listUser(filter, fields)).data);
```

