An open API service indexing awesome lists of open source software.

https://github.com/jumpn/absinthe-phoenix-socket-relay

Absinthe Phoenix Socket Relay
https://github.com/jumpn/absinthe-phoenix-socket-relay

absinthe absinthe-graphql absinthe-phoenix relay relay-modern

Last synced: 3 months ago
JSON representation

Absinthe Phoenix Socket Relay

Awesome Lists containing this project

README

          

# @jumpn/absinthe-phoenix-socket-relay

> Absinthe Phoenix Socket Relay

- [Installation](#installation)
- [Using npm](#using-npm)
- [Using yarn](#using-yarn)
- [Examples](#examples)
- [API](#api)
- [createFetcher](#createfetcher)
- [createSubscriber](#createsubscriber)
- [isSubscribed](#issubscribed)
- [References](#references)
- [License](#license)

## Installation

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

$ npm install --save @jumpn/absinthe-phoenix-socket-relay

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

$ yarn add @jumpn/absinthe-phoenix-socket-relay

## Examples

- **relay-environment.js**

```javascript
// @flow

import {createFetcher, createSubscriber} from "@absinthe-phoenix-socket-relay";
import {Environment, Network} from "relay-runtime";

import absintheSocket from "./absintheSocket";

export default new Environment({
network: Network.create(
createFetcher(absintheSocket),
createSubscriber(absintheSocket)
),
store: new Store(new RecordSource())
});
```

## API

### createFetcher

Creates a Fetcher (Relay FetchFunction) using the given AbsintheSocket
instance

**Parameters**

- `absintheSocket` **AbsintheSocket**
- `onError` **function (error: [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)): any**

Returns **FetchFunction**

### createSubscriber

Creates a Subscriber (Relay SubscribeFunction) using the given AbsintheSocket
instance

**Parameters**

- `absintheSocket` **AbsintheSocket**
- `onRecoverableError` **function (error: [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)): any**

Returns **SubscribeFunction**

### isSubscribed

Returns a promise that resolves to `true` in case subscription of given
disposable has started or to `false` otherwise

**Parameters**

- `disposable` **Disposable**

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>**

## References

- [Absinthe Phoenix Socket](https://github.com/jumpn/absinthe-phoenix-socket)
- **Relay**
- [Environment](https://facebook.github.io/relay/docs/relay-environment.html)
- [NetworkLayer](https://facebook.github.io/relay/docs/network-layer.html)
- [FetchFunction](https://github.com/facebook/relay/blob/master/packages/relay-runtime/network/RelayNetworkTypes.js#L79)
- [SubscribeFunction](https://github.com/facebook/relay/blob/master/packages/relay-runtime/network/RelayNetworkTypes.js#L93)

## License

[MIT](LICENSE.txt) :copyright: **Jumpn Limited** / Mauro Titimoli (mauro@jumpn.com)