Skip to content

Commit 99a9225

Browse files
committed
docs(readme): document
1 parent c608581 commit 99a9225

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1-
# Library TS Boilerplate
1+
# Mikro GraphQL Flusher
2+
3+
GraphQL bulk-operation solution for MikroORM in Nest.
4+
5+
> This package internally uses `AsyncLocalStorage` to count mutations in requests, which may have [a slight negative impact on the performance](https://github.com/nodejs/node/issues/34493#issuecomment-845094849).
6+
7+
## Installation
8+
9+
```
10+
npm i @nestjs-devkit/mikro-graphql-flusher
11+
```
12+
13+
## Why?
14+
15+
The GraphQL runtime has built-in support for bulk-operations, which means you can send an array of GraphQL queries and mutations in a single HTTP request and receive an array of results.
16+
17+
While, in Nest, all bulk queries and mutations are handled in parallel. Therefore, when there are multiple mutations in a request, invoking `em.flush()` in resolvers will usually conflict and causes errors because `em.flush()` is not allowed to be invoked when another invoke is pending.
18+
19+
So how will we solve this problem? By importing the `MikroFlusherModule`, a global interceptor will be registered that will defer the return of each mutation after it has been handled. When all the mutations in the request have been deferred, the interceptor will invoke `em.flush()` to save the changes of all these mutations, and then return the results of all these mutations at once.
20+
21+
You can send bulk-operation requests to your GraphQL server now, and you don't need to invoke `em.flush()` manually any more! How wonderful!
22+
23+
## Tutorial
24+
25+
As said before, the only thing we need to do is to import the `MikroFlusherModule`:
26+
27+
```ts
28+
@Module({
29+
imports: [
30+
MikroFlusherModule,
31+
// ...
32+
],
33+
})
34+
export class AppModule {}
35+
```
36+
37+
Done! (applies to Express only)
38+
39+
## Contributing
40+
41+
Pull requests are always welcome! ;]

0 commit comments

Comments
 (0)