# gqlcacheclient

> A Simple JS GraphQL Caching Client

Latest version **1.0.16** (published 2019-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install gqlcacheclient
pnpm add gqlcacheclient
yarn add gqlcacheclient
bun add gqlcacheclient
```

## 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 | 1.0.16 |
| Published | 2019-02-15 |
| First published | 2018-08-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 362.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | tianhai |
| Maintainers | tianhai82 |
| Keywords | graphql, cache, js, browser, client |

## Links

- npm: https://www.npmjs.com/package/gqlcacheclient
- Repository: https://github.com/tianhai82/gqlcacheclient
- Homepage: https://github.com/tianhai82/gqlcacheclient#readme
- Issues: https://github.com/tianhai82/gqlcacheclient/issues
- npm.io page: https://npm.io/package/gqlcacheclient

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) >=4.17.11
- [graphql](https://npm.io/package/graphql.md) ^0.13.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.16 (latest) — 2019-02-15
- 1.0.1 (1.0.1) — 2018-08-02
- 1.0.15 — 2018-08-10
- 1.0.14 — 2018-08-10
- 1.0.13 — 2018-08-08
- 1.0.12 — 2018-08-08
- 1.0.11 — 2018-08-08
- 1.0.10 — 2018-08-08
- 1.0.9 — 2018-08-07
- 1.0.8 — 2018-08-06
- 1.0.7 — 2018-08-03
- 1.0.5 — 2018-08-02
- 1.0.4 — 2018-08-02
- 1.0.3 — 2018-08-02
- 1.0.2 — 2018-08-02
- … 1 more at https://npm.io/package/gqlcacheclient/versions

## README

# gqlcacheclient

📡 A Simple and Minimalistic JS GraphQL caching client for the browsers

## Features

* **simple and lightweight** GraphQL client
* Promise-based API (works with `async` / `await`)


## Install

```sh
npm install gqlcacheclient
yarn add gqlcacheclient
```

## Quickstart

```js
import GqlClient = 'gqlcacheclient'

const query = `{
  Movie(title: "Inception") {
    releaseDate
    actors {
      name
    }
  }
}`

const client = new GqlClient('https://api.graph.cool/simple/v1/movies')
client.request(query).then(data => console.log(data))

```
Results will be cached based on the query, fields and arguments. When you make a second query for less fields than the first query, a new query will be made to the server. All fields and arguments must match for the query to return data from the cache.

## Usage

```js
import GqlClient = 'gqlcacheclient'

const headers = {
  'Content-Type': 'application/graphql',
  credentials: 'same-origin',
};

// errHandler allows you to handle errors before rethrowing the errors. If no error is rethrown,
//   the request will resolve with the data returned from this errHandler.
//   Otherwise, the request be able to catch the error rethrown
//   Check for networkError or graphqlError in the (err) parameter
const errHandler = (err) => {
    // check for networkError or graphqlError and handle them
    if (err.networkError.status === 401){
        // forward to login page
    }
    throw err; //rethrow err
}
const client = new GqlClient('https://api.graph.cool/simple/v1/movies',headers, errHandler)
// if no header is provided, the default will be {'Content-Type': 'application/json; charset=utf-8'}

const query = `query getMovie($title: String!) {
  Movie(title: $title) {
    releaseDate
    actors {
      name
    }
  }
}`

const variables = {
  title: 'Inception',
}

// currently, options takes only { cache: true } or { cache: false }
const options = {
  cache: true // default is true
};

client.request(query, variables, options)
  .then(data => console.log(data))
  .catch(err => {
    console.log(err) // handle errors
  })
```

## FAQ

### Does it support inline fragment?

Yes!


### Does it support fragment?

Not yet.

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