# @theorchard/dataloader-zod

A thin wrapping DataLoader to parse & transform the returned values from another DataLoader

## Usage

```ts
const myZodSchema = z.(...);

const myDataLoader = new ZodDataLoader(
    new DataLoader(...), // Any dataloader
    myZodSchema,
);
```

### Example with `@theorchard/dataloader-cypher`

`dataloader-cypher` returns an `unknown` type, so you can use the `ZodDataLoader` to validate the response:

```ts
import { neo4j } from '@theorchad/connector-neo4j';

const myZodSchema = z.object({
    string: z.string(),
    // If you include something that is not turned in to a JS primative, you can use:
    integer: z.instanceOf(neo4j.types.Integer),
});

const dataloader = new ZodDataLoader(
    new CypherDataLoader<string>(
        neo4jDriver,
        `
            UNWIND $keys AS key
            RETURN key, {
                string: "string",
                integer: 10
            }
        `
    ),
    myZodSchema
);

// Result will be typed according to your zod schema
const result = await dataloader.load('an-id');
```
