# @nestjs-devkit/mikro-graphql-flusher

> GraphQL bulk-operation solution for MikroORM in Nest.

Latest version **0.1.0** (published 2022-01-07) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @nestjs-devkit/mikro-graphql-flusher
pnpm add @nestjs-devkit/mikro-graphql-flusher
yarn add @nestjs-devkit/mikro-graphql-flusher
bun add @nestjs-devkit/mikro-graphql-flusher
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2022-01-07 |
| First published | 2022-01-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 30.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | char2s |

## Links

- npm: https://www.npmjs.com/package/@nestjs-devkit/mikro-graphql-flusher
- Repository: https://github.com/nestjs-devkit/mikro-graphql-flusher
- Homepage: https://github.com/nestjs-devkit/mikro-graphql-flusher#readme
- Issues: https://github.com/nestjs-devkit/mikro-graphql-flusher/issues
- npm.io page: https://npm.io/package/@nestjs-devkit/mikro-graphql-flusher

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^2.3.1
- [advanced-promises](https://npm.io/package/advanced-promises.md) ^1.0.0-beta.13

## Recent versions

- 0.1.0 (latest) — 2022-01-07

## README

# Mikro GraphQL Flusher

GraphQL bulk-operation solution for MikroORM in Nest.

> 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).

## Installation

```
npm i @nestjs-devkit/mikro-graphql-flusher
```

## Why?

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.

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.

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.

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!

## Tutorial

As said before, the only thing we need to do is to import the `MikroFlusherModule`:

```ts
@Module({
  imports: [
    MikroFlusherModule,
    // ...
  ],
})
export class AppModule {}
```

Done! (applies to Express only)

## Contributing

Pull requests are always welcome! ;]

---
_Source: https://npm.io/package/@nestjs-devkit/mikro-graphql-flusher · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
