# graphcool-lib

> ## Install

Latest version **0.1.4** (published 2017-10-23) · 0 weekly downloads

## Install

```sh
npm install graphcool-lib
pnpm add graphcool-lib
yarn add graphcool-lib
bun add graphcool-lib
```

## Health

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

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2017-10-23 |
| First published | 2017-06-23 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | timsuchanek, sorenbs, schickling |

## Links

- npm: https://www.npmjs.com/package/graphcool-lib
- npm.io page: https://npm.io/package/graphcool-lib

## Dependencies (7)

- [graphql](https://npm.io/package/graphql.md) ^0.11.2
- [node-fetch](https://npm.io/package/node-fetch.md) ^1.7.3
- [apollo-link](https://npm.io/package/apollo-link.md) ^0.7.0
- [graphql-tools](https://npm.io/package/graphql-tools.md) ^2.4.0
- [graphql-request](https://npm.io/package/graphql-request.md) ^1.3.4
- [apollo-link-http](https://npm.io/package/apollo-link-http.md) ^0.7.0
- [source-map-support](https://npm.io/package/source-map-support.md) ^0.4.17

## Recent versions

- 0.1.4 (latest) — 2017-10-23
- 0.0.4-beta4 (beta) — 2017-10-16
- 0.1.3 — 2017-10-19
- 0.1.2 — 2017-10-19
- 0.1.1 — 2017-10-19
- 0.1.0 — 2017-10-18
- 0.0.4-beta3 — 2017-10-13
- 0.0.4-beta2 — 2017-09-02
- 0.0.4-beta — 2017-09-02
- 0.0.3 — 2017-07-10
- 0.0.2 — 2017-07-08
- 0.0.1 — 2017-07-08
- 0.0.0 — 2017-06-23

## README

# graphcool-lib

## Install

```sh
yarn add graphcool-lib
```

## Usage

### `.api()`
#### Typescript
```ts
import { fromEvent, default as Graphcool, FunctionEvent } from 'graphcool-lib'

interface User {
  id: string
}

export default async (event: FunctionEvent) => {
  const lib: Graphcool = fromEvent(event)
  const client = lib.api('simple/v1')
  const {allUsers} = await client.request<{allUsers: User[]}>(`{allUsers{id}}`)

  return {
    data: {
      event: allUsers
    }
  }
}
```
#### Javascript
```js
import { fromEvent } from 'graphcool-lib'

export default async event => {
  const lib = fromEvent(event)
  const client = lib.api('simple/v1')
  const {allUsers} = await client.request(`{allUsers{id}}`)

  return {
    data: {
      event: allUsers
    }
  }
}

```

### `.generateNodeToken(nodeId, modelName)`
Using `.generateNodeToken` you can act on behalf of a User:
```ts
import { fromEvent } from 'graphcool-lib'

export default async event => {
  const client = fromEvent(event)
  const onbehalfToken = await client.generateAuthToken('cj8a9rex1i5eg0170k116mfme', 'User')
  const api = client.api('simple/v1', {token: onbehalfToken})
  const result = await api.request(`{allUsers{id}}`)

  return {
    data: {
      message: {
        result,
      }
    }
  }
}
```

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