# @barejs/graphql-observable

> GraphQL observable clients for the Python bareASGI web toolkit

Latest version **6.0.0** (published 2022-03-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @barejs/graphql-observable
pnpm add @barejs/graphql-observable
yarn add @barejs/graphql-observable
bun add @barejs/graphql-observable
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2022-03-21 |
| First published | 2019-08-15 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 29.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Rob Blackbourn |
| Maintainers | rob-blackbourn |
| Keywords | graphql, client, bareasgi, observable, rxjs |

## Links

- npm: https://www.npmjs.com/package/@barejs/graphql-observable
- Repository: https://github.com/rob-blackbourn/barejs-graphql-observable
- Issues: https://github.com/rob-blackbourn/barejs-graphql-observable/issues
- npm.io page: https://npm.io/package/@barejs/graphql-observable

## Dependencies (2)

- [rxjs](https://npm.io/package/rxjs.md) ^6.5.2
- [@barejs/graphql-client](https://npm.io/package/@barejs/graphql-client.md) ^6.0.0

## 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

- 6.0.0 (latest) — 2022-03-21
- 6.0.0-rc1 — 2022-03-20
- 5.0.6 — 2021-09-20
- 5.0.5 — 2021-04-26
- 5.0.4 — 2021-04-26
- 5.0.3 — 2021-04-26
- 5.0.2 — 2021-04-07
- 5.0.1 — 2021-04-07
- 5.0.0 — 2021-03-14
- 4.0.0 — 2020-04-03
- 3.0.0 — 2019-10-15
- 0.1.0 — 2019-08-15

## README

# @barejs/graphql-observable

This is a collection of observable GraphQL clients which support queries, mutations and subscriptions.
It uses the
[rxjs](https://rxjs-dev.firebaseapp.com/) 
observable library.

It specifically targets the 
[bareASGI GraphQL](https://github.com/rob-blackbourn/bareASGI-graphql-next)
module from the
[bareASGI](https://github.com/rob-blackbourn/bareASGI)
python web framework, which provides multiple transports for subscriptions.

This is a thin wrapper around
[@barejs/graphql-client](https://github.com/rob-blackbourn/barejs-graphql-client)
where more documentation can be found.

## Usage

### Subscriptions

The `graphqlObservableWsSubscriber` function used be used for subscriptions.

```js
import { graphqlObservableWsSubscriber } from '@barejs/graphql-observable'

const url = 'http://www.example.com/subscriptions'
const init = {}

const query = 'subscription { someSubscription { someField someOtherField } }'
const variables = null
const operationName = null

subscription = graphqlObservableWsSubscriber(url, init, query, variables, operationName).subscribe({
  next: data => console.log(data),
  error: error => console.error(error),
  complete: () => console.log('Completed')
})
```

### Queries, Mutations and Subscriptions

The `graphqlObservableWsClient` can be used for queries, mutations, and subscriptions.

```js
import { graphqlObservableWsClient } from '@barejs/graphql-observable'

const url = 'http://www.example.com/graphql'
const init = {}

// This could be a query, mutation or subscription.
const query = 'subscription { someSubscription { someField someOtherField } }'
const variables = null
const operationName = null

const subscription = graphqlObservableWsClient(
  url,
  init,
  query,
  variables,
  operationName)
  .subscribe({
    next: data => console.log(data),
    error: error => console.log(error),
    complete: () => console.log('complete')
  })

// Later ...
subscription.unsubscribe()
```

### Other transports

In addition to the fetch/WebSocket transports there is support for `EventSource` and streaming fetch, although these are only supported by the bareASGI web framework.

The following functions are available:

*  graphqlObservableEventSourceClient,
*  graphqlObservableEventSourceSubscriber,
*  graphqlObservableFetchClient,
*  graphqlObservableStreamClient,
*  graphqlObservableWsClient,
*  graphqlObservableWsSubscriber

All of the clients abd subscribers take the same arguments as the WebSocket variant.

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