@envelop/dataloader 3.4.0-alpha-26c4ae2.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
## `@envelop/dataloader`
|
|
2
|
+
|
|
3
|
+
This plugin helps you to create a new [DataLoader](https://github.com/graphql/dataloader) instance every time your context is being built. The created instance is injected into the `context` with the name your wish to use.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
yarn add dataloader @envelop/dataloader
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage Example
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { envelop } from '@envelop/core';
|
|
15
|
+
import DataLoader from 'dataloader';
|
|
16
|
+
import { useDataLoader } from '@envelop/dataloader';
|
|
17
|
+
|
|
18
|
+
const getEnveloped = envelop({
|
|
19
|
+
plugins: [
|
|
20
|
+
// ... other plugins ...
|
|
21
|
+
useDataLoader('users', context => new DataLoader(keys => myBatchGetUsers(keys))),
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Then, when you need to use it in your resolvers, just take it from the context:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
export const resolvers = {
|
|
30
|
+
Query: {
|
|
31
|
+
user: (root, args, context, info) => {
|
|
32
|
+
return context.users.load(args.id);
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Notes
|
|
39
|
+
|
|
40
|
+
There are several ways to create and use DataLoader, please refer to: https://github.com/graphql/dataloader#caching-per-request for more details.
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/dataloader",
|
|
3
|
-
"version": "3.4.0
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "2.4.0
|
|
6
|
+
"@envelop/core": "^2.4.0",
|
|
7
7
|
"dataloader": "^2.0.0",
|
|
8
8
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
9
9
|
},
|