# apollo-link-rxjs

> Use RxJS with ApolloLink

Latest version **1.0.0-alpha.1** (published 2018-04-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install apollo-link-rxjs
pnpm add apollo-link-rxjs
yarn add apollo-link-rxjs
bun add apollo-link-rxjs
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.1 |
| Published | 2018-04-20 |
| First published | 2018-04-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 30 |
| Author | Kamil Kisiela |
| Maintainers | kamilkisiela |
| Keywords | apollo, graphql, apollo-link, rxjs |

## Links

- npm: https://www.npmjs.com/package/apollo-link-rxjs
- Repository: https://github.com/kamilkisiela/apollo-link-rxjs
- Homepage: https://github.com/kamilkisiela/apollo-link-rxjs#readme
- Issues: https://github.com/kamilkisiela/apollo-link-rxjs/issues
- npm.io page: https://npm.io/package/apollo-link-rxjs

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 1.0.0-alpha.1 (latest) — 2018-04-20
- 1.0.0-alpha.0 — 2018-04-19

## README

# RxJS with ApolloLink

[![npm version](https://badge.fury.io/js/apollo-link-rxjs.svg)](https://badge.fury.io/js/apollo-link-rxjs)
[![CircleCI](https://circleci.com/gh/kamilkisiela/apollo-link-rxjs.svg?style=svg)](https://circleci.com/gh/kamilkisiela/apollo-link-rxjs)

## Purpose

To use goods of RxJS in Apollo ecosystem

## Installation

```
yarn add apollo-link-rxjs
npm install --save apollo-link-rxjs
```

## Usage

The link accepts two options:

* `onResult`
* `onOperation`

Both are functions, that gets an `Observable` as an argument and returns an `Observable`.

The `onResult` transforms `FetchResult` (of ApolloLink) - the result of terminating link (links like HttpLink).
The `onOperation` transforms `Operation` (of ApolloLink)

```ts
import { execute, ApolloLink } from 'apollo-link';
import { HttpLink } from 'apollo-link-http';
import { rxjs } from 'apollo-link-rxjs';
// or RxjsLink and new RxjsLink(sameOptionsAsRxjs)
import { retry, tap } from 'rxjs/operators';
import gql from 'graphql-tag';

const operation = {
  query: gql`
    query hello {
      hello
    }
  `,
};

// regular Apollo link
const httpLink = new HttpLink({ uri: '/graphql' });

// RxJS !1one
const rxjsLink = rxjs({
  onResult(obs => obs.pipe(
    retry(3),
  )),
  onOperation(obs => obs.pipe(
    tap(operation => operation.setContext({
      includeExtensions: true
    }))
  ))
});

const link = ApolloLink.from([rxjsLink, httpLink]);

execute(link, operation).subscribe({
  next: result => {
    // calling the graphql endpoint less then 3 times succeed
    console.log(result);
  },
  error: error => {
    // calling the graphql endpoint 3 times failed
    console.log(error);
  }
});
```

> NOTE: Right now it's more like a Proof of Concept than the actual implementation

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