npm package: @kanmii/socket-apollo-link
Description: Absinthe Socket Apollo Link
Author: Mauro Titimoli
Latest version: 0.2.4

# @absinthe/socket-apollo-link

> Absinthe Socket Apollo Link

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<!-- END doctoc -->

- [Installation](#installation)
  - [Using npm](#using-npm)
  - [Using yarn](#using-yarn)
- [Examples](#examples)
- [API](#api)
  - [createAbsintheSocketLink](#createabsinthesocketlink)
    - [Parameters](#parameters)
- [References](#references)
- [License](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Installation

### Using [npm](https://docs.npmjs.com/cli/npm)

    $ npm install --save @absinthe/socket-apollo-link

### Using [yarn](https://yarnpkg.com)

    $ yarn add @absinthe/socket-apollo-link

## Examples

1.  Create AbsintheSocketLink (`absinthe-socket-link.js`)

```javascript
// @flow

import * as AbsintheSocket from "@absinthe/socket";
import {createAbsintheSocketLink} from "@absinthe/socket-apollo-link";
import {Socket as PhoenixSocket} from "phoenix";

export default createAbsintheSocketLink(AbsintheSocket.create(
  new PhoenixSocket("ws://localhost:4000/socket")
));
```

2.  Send all the operations using AbsintheSocketLink

```javascript
// @flow

import ApolloClient from "apollo-client";
import {InMemoryCache} from "apollo-cache-inmemory";

// see example 1
import absintheSocketLink from "./absinthe-socket-link";

const client = new ApolloClient({
  link: absintheSocketLink,
  cache: new InMemoryCache()
});
```

3.  Subscribe using AbsintheSocketLink and send queries and mutations using HttpLink

```javascript
// @flow

import ApolloClient from "apollo-client";
import {createHttpLink} from "apollo-link-http";
import {hasSubscription} from "@jumpn/utils-graphql";
import {InMemoryCache} from "apollo-cache-inmemory";
import {split} from "apollo-link";

// see example 1
import absintheSocketLink from "./absinthe-socket-link";

const link = split(
  operation => hasSubscription(operation.query),
  absintheSocketLink,
  createHttpLink({uri: "/graphql"})
);

const client = new ApolloClient({
  link,
  cache: new InMemoryCache()
});
```

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### createAbsintheSocketLink

Creates a terminating ApolloLink to request operations using given
AbsintheSocket instance

#### Parameters

-   `absintheSocket` **AbsintheSocket** 
-   `onError` **$ElementType&lt;Observer&lt;Result, Variables>, `"onError"`>** 
-   `onStart` **$ElementType&lt;Observer&lt;Result, Variables>, `"onStart"`>** 

## References

-   [Absinthe Phoenix Socket](https://github.com/absinthe-graphql/absinthe-socket/tree/master/packages/socket)
-   **Apollo Link**
    -   [Apollo Client](http://apollo-link-docs.netlify.com/docs/link/#apollo-client)
    -   [Terminating Links](http://apollo-link-docs.netlify.com/docs/link/overview.html#terminating)
    -   [Directional Composition](http://apollo-link-docs.netlify.com/docs/link/composition.html#directional)
    -   [Http Link](http://apollo-link-docs.netlify.com/docs/link/links/http.html)

## License

[MIT](LICENSE.txt) :copyright: Jumpn Limited.