# @forrestjs/service-hasura-client

> NodeJS client to issue GraphQL queries towards an Hasura endpoint, and Hasura admin APIs

Latest version **5.2.2** (published 2024-03-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @forrestjs/service-hasura-client
pnpm add @forrestjs/service-hasura-client
yarn add @forrestjs/service-hasura-client
bun add @forrestjs/service-hasura-client
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.2.2 |
| Published | 2024-03-18 |
| First published | 2022-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 43 |
| Author | Marco Pegoraro |
| Maintainers | marcopeg |
| Keywords | forrestjs, service, hasura, client, graphql |

## Links

- npm: https://www.npmjs.com/package/@forrestjs/service-hasura-client
- Repository: https://github.com/forrestjs/forrestjs.git#master
- Homepage: https://github.com/forrestjs/forrestjs/tree/master/packages/service-hasura-client#readme
- Issues: https://github.com/forrestjs/forrestjs/issues
- npm.io page: https://npm.io/package/@forrestjs/service-hasura-client

## Dependencies (1)

- [@forrestjs/core](https://npm.io/package/@forrestjs/core.md) ^5.2.2

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 5.2.2 (latest) — 2024-03-18
- 5.2.1 — 2023-03-21
- 5.2.0 — 2023-03-21
- 5.1.1 — 2023-03-21
- 5.1.0 — 2023-03-21
- 5.0.6 — 2023-03-20
- 5.0.5 — 2023-03-14
- 5.0.4 — 2023-03-14
- 5.0.3 — 2023-03-12
- 5.0.2 — 2023-03-12
- 5.0.1 — 2023-03-12
- 5.0.0-alpha.40 — 2023-03-12
- 5.0.0-alpha.39 — 2023-03-10
- 5.0.0-alpha.38 — 2023-03-10
- 5.0.0-alpha.37 — 2023-03-10
- … 44 more at https://npm.io/package/@forrestjs/service-hasura-client/versions

## README

# Hasura Client for NodeJS

## Configuration

```js
forrest.run({
  settings: {
    hasura: {
      endpoint: 'http://localhost:8080',
      secret: 'hasura',
      auth: {
        token: 'token',
        jwt: {
          secret: 'abc',
          roles: ['r1', 'r2'],
          defaultRole: ['r1'],
          session: {
            foo: 'bar'
          }
        },
        fn: async () => ({
          token: 'token',
          ttl: 0
        })
      } 
    }
  }
})
```

> 👉 Only **one** auth setting is supported at any time.

### Authorization Token

When you provide this setting, HasuraClient will use it as `Authorization: Bearer {token}`.

### Authorization JWT

[[ TO BE IMPLEMENTED ]]

When you provide this setting, HasuraClient will calculate the JWT and use it as `Authorization: Bearer {jwt}`.

### Authorization Logic

[[ TO BE IMPLEMENTED ]]

When you provide this setting you can calculate the authorization token by offering a custom logic.

- the resulting `token` key will be used as `Authorization: Bearer {token}`.
- the `ttl` will be used as cache flag:
  - `0` keep forever (until reboot)
  - `-1` calculate at every query
  - `1000` keep for 1s (integer value expressed in _milliseconds_)

## Query

```js
const MY_QUERY = `
  query FooBar ($var: String!) {
    resource (
      par: $var
    ) {
      field1
      field2
    }
  }
`;

const myFeature = () => [{
  target: '$START_FEATURE',
  handler: async ({ getContext }) => {
    const hasura = getContext('hasura');
    const res = await hasura.query(MY_QUERY, {
      var: 'foobar'
    });

    console.log(res);
  }
}];
```

## Sql

```js
const myFeature = () => [{
  target: '$START_FEATURE',
  handler: async ({ getContext }) => {
    const hasura = getContext('hasura');
    const res = await hasura.sql(MY_QUERY, {
      var: 'foobar'
    });

    console.log(res);
  }
}];
```

---
_Source: https://npm.io/package/@forrestjs/service-hasura-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
