# graphql-firehose-transformer

> Add a simple interceptor to all of your Amplify API mutations and queries!

Latest version **0.9.0-beta** (published 2021-06-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-firehose-transformer
pnpm add graphql-firehose-transformer
yarn add graphql-firehose-transformer
bun add graphql-firehose-transformer
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.0-beta |
| Published | 2021-06-01 |
| First published | 2021-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 30.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Laguna Health |
| Maintainers | rotembentzur |
| Keywords | aws, amplify, graphql, transformer, interceptor, firehose, audit, log, logging |

## Links

- npm: https://www.npmjs.com/package/graphql-firehose-transformer
- Repository: https://github.com/LaugnaHealth/graphql-firehose-transformer
- Homepage: https://github.com/LaugnaHealth/graphql-firehose-transformer#readme
- Issues: https://github.com/LaugnaHealth/graphql-firehose-transformer/issues
- npm.io page: https://npm.io/package/graphql-firehose-transformer

## Dependencies (3)

- [graphql](https://npm.io/package/graphql.md) ^14.5.8
- [graphql-transformer-core](https://npm.io/package/graphql-transformer-core.md) ^6.21.7
- [graphql-transformer-common](https://npm.io/package/graphql-transformer-common.md) ^4.17.11

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.9.0-beta (latest) — 2021-06-01
- 0.9.0-alpha — 2021-05-24

## README

> 🚒 Add a simple interceptor to all of your Amplify API mutations and queries!

# graphql-firehose-transformer

[![Pull requests are welcome!](https://img.shields.io/badge/PRs-welcome-brightgreen)](#contribute-)
[![npm](https://img.shields.io/npm/v/graphql-firehose-transformer)](https://www.npmjs.com/package/graphql-firehose-transformer)
[![GitHub license](https://img.shields.io/github/license/LaugnaHealth/graphql-firehose-transformer)](https://github.com/LaugnaHealth/graphql-firehose-transformer/blob/master/LICENSE)

## Installation

`npm install --save graphql-firehose-transformer`

## How to use

### Setup custom transformer

Edit `amplify/backend/api/<YOUR_API>/transform.conf.json` and append `"graphql-firehose-transformer"` to the `transformers` field.

```json
"transformers": [
    "graphql-firehose-transformer"
]
```

### Use @firehose directive

Append `@firehose` to target types and add the name of the separately deployed function that should be called for every mutation and query to this type as argument.

```graphql
type Todo @model @firehose(name: "auditlog-${env}") {
  id: ID!
  title: String!
  description: String
}
```

In this example, the `auditlog-${env}` lambda will be called before every mutation or query to the `Todo` type, which is ideal to build an audit logger for example.

**If you deployed your function using the 'amplify function' category**

The Amplify CLI provides support for maintaining multiple environments out of the box. When you deploy a function via `amplify add function`, it will automatically add the environment suffix to your Lambda function name. For example if you create a function named **auditlog** using `amplify add function` in the **dev** environment, the deployed function will be named **auditlog-dev**. The `@firehose` directive allows you to use `${env}` to reference the current Amplify CLI environment.

```graphql
type Todo @model @firehose(name: "auditlog-${env}") {
  id: ID!
  title: String!
  description: String
}
```

**If you deployed your function without amplify**

If you deployed your API without amplify then you must provide the full Lambda function name. If you deployed the same function with the name **auditlog** then you would have:

```graphql
type Todo @model @firehose(name: "auditlog") {
  id: ID!
  title: String!
  description: String
}
```

#### Calling functions in different regions

By default, you expect the function to be in the same region as the amplify project. If you need to call a function in a different (or static) region, you can provide the **region** argument.

```graphql
type Todo @model @firehose(name: "auditlog", region: "us-east-1") {
  id: ID!
  title: String!
  description: String
}
```

Calling functions in different AWS accounts is not supported via the @firehose directive but is supported by AWS AppSync.

#### Structure of the function event

When writing lambda functions that are connected via the `@firehose` directive, you can expect the following structure for the AWS Lambda event object.

| Key       | Description                                                                                                                                                            |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| typeName  | Either `Mutation` or `Query`.                                                                                                                                          |
| fieldName | The mutation or query type field that was called, e.g. `createTodo`.                                                                                                   |
| arguments | A map containing the arguments passed to the field being resolved.                                                                                                     |
| identity  | A map containing identity information for the request. Contains a nested key 'claims' that will contains the JWT claims if they exist.                                 |
| source    | When resolving a nested field in a query, the source contains parent value at runtime. For example when resolving `Post.comments`, the source will be the Post object. |
| request   | The AppSync request object. Contains header information.                                                                                                               |
| prev      | When using pipeline resolvers, this contains the object returned by the previous function. You can return the previous value for auditing use cases.                   |

## Contribute 🦸

Please feel free to create, comment and of course solve some of the issues. To get started you can also go for the easier issues marked with the `good first issue` label if you like.

### Development

- It is important to always make sure the version of the installed `graphql` dependency matches the `graphql` version the `graphql-transformer-core` depends on.

## License

The [MIT License](LICENSE)

## Credits

The _graphql-firehose-transformer_ library is maintained and sponsored by [Laguna Health](https://www.lagunahealth.com/), a digital recovery assurance company fusing data, technology, and live behavioral health experts to shorten recovery times and reduce readmissions.

Shout-out to the Swiss web and mobile app developer [Florian Gyger](https://github.com/flogy) who built the initial version of this library.

---
_Source: https://npm.io/package/graphql-firehose-transformer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
