Skip to content

Commit ee6361b

Browse files
committed
doc(README): remove references to invalid DataLoader import
1 parent 94d8b3c commit ee6361b

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
# NestJS Dataloader
2+
23
NestJS dataloader simplifies adding [graphql/dataloader](https://github.com/graphql/dataloader) to your NestJS project. DataLoader aims to solve the common N+1 loading problem.
34

45
## Installation
56

67
Install with yarn
7-
``` bash
8+
9+
```bash
810
yarn add nestjs-dataloader
911
```
1012

1113
Install with npm
12-
``` bash
14+
15+
```bash
1316
npm install --save nestjs-dataloader
14-
```
17+
```
1518

1619
## Usage
20+
1721
### NestDataLoader Creation
18-
We start by implementing the ```NestDataLoader``` interface. This tells ```DataLoader``` how to load our objects.
1922

20-
``` typescript
21-
import * as DataLoader from 'dataloader';
23+
We start by implementing the `NestDataLoader` interface. This tells `DataLoader` how to load our objects.
24+
25+
```typescript
26+
import DataLoader from 'dataloader';
2227
import { Injectable } from '@nestjs/common';
2328
import { NestDataLoader } from 'nestjs-dataloader';
2429
...
@@ -27,18 +32,19 @@ import { NestDataLoader } from 'nestjs-dataloader';
2732
export class AccountLoader implements NestDataLoader<string, Account> {
2833
constructor(private readonly accountService: AccountService) { }
2934

30-
generateDataLoader(): DataLoader<string, Account> {
35+
generateDataLoader(): DataLoader<string, Account> {
3136
return new DataLoader<string, Account>(keys => this.accountService.findByIds(keys));
3237
}
3338
}
3439
```
3540

36-
The first generic of the interface is the type of ID the datastore uses. The second generic is the type of object that will be returned. In the above instance, we want ```DataLoader``` to return instances of the ```Account``` class.
41+
The first generic of the interface is the type of ID the datastore uses. The second generic is the type of object that will be returned. In the above instance, we want `DataLoader` to return instances of the `Account` class.
3742

3843
### Providing the NestDataLoader
44+
3945
For each NestDataLoader we create, we need to provide it to our module.
4046

41-
``` typescript
47+
```typescript
4248
import { Module } from '@nestjs/common';
4349
import { APP_INTERCEPTOR } from '@nestjs/core';
4450
import {DataLoaderInterceptor} from 'nestjs-dataloader'
@@ -59,9 +65,11 @@ export class ResolversModule { }
5965
```
6066

6167
### Using the NestDataLoader
68+
6269
Now that we have a dataloader and our module is aware of it, we need to pass it as a parameter to an endpoint in our graphQL resolver.
63-
``` typescript
64-
import * as DataLoader from 'dataloader';
70+
71+
```typescript
72+
import DataLoader from 'dataloader';
6573
import { Loader } from 'nestjs-dataloader';
6674
...
6775

@@ -76,6 +84,9 @@ export class AccountResolver {
7684
}
7785
}
7886
```
79-
The important thing to note is that the parameter of the ```@Loader``` decorator is the name of the ```NestDataLoader``` class we want to be injected to the method. The DataLoader library will handle bulk retrieval and caching of our requests. Note that the caching is stored on a per-request basis.
87+
88+
The important thing to note is that the parameter of the `@Loader` decorator is the name of the `NestDataLoader` class we want to be injected to the method. The DataLoader library will handle bulk retrieval and caching of our requests. Note that the caching is stored on a per-request basis.
89+
8090
## Contributing
91+
8192
Pull requests are always welcome. For major changes, please open an issue first to discuss what you would like to change.

0 commit comments

Comments
 (0)