Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jumpn/absinthe-phoenix-socket-apollo-link
Absinthe Phoenix Socket Apollo Link
https://github.com/jumpn/absinthe-phoenix-socket-apollo-link
absinthe absinthe-graphql absinthe-phoenix apollo apollo-client apollographql graphql socket
Last synced: about 2 months ago
JSON representation
Absinthe Phoenix Socket Apollo Link
- Host: GitHub
- URL: https://github.com/jumpn/absinthe-phoenix-socket-apollo-link
- Owner: jumpn
- License: mit
- Created: 2017-11-01T05:26:28.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-01T05:30:43.000Z (almost 7 years ago)
- Last Synced: 2024-06-30T02:55:37.609Z (3 months ago)
- Topics: absinthe, absinthe-graphql, absinthe-phoenix, apollo, apollo-client, apollographql, graphql, socket
- Language: JavaScript
- Size: 68.4 KB
- Stars: 2
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# @jumpn/absinthe-phoenix-socket-apollo-link
> Absinthe Phoenix Socket Relay
- [Installation](#installation)
- [Using npm](#using-npm)
- [Using yarn](#using-yarn)
- [Examples](#examples)
- [API](#api)
- [createAbsintheSocketLink](#createabsinthesocketlink)
- [References](#references)
- [License](#license)## Installation
### Using [npm](https://docs.npmjs.com/cli/npm)
$ npm install --save @jumpn/absinthe-phoenix-socket-apollo-link
### Using [yarn](https://yarnpkg.com)
$ yarn add @jumpn/absinthe-phoenix-socket-apollo-link
## Examples
1. Create AbsintheSocketLink (`absinthe-socket-link.js`)
```javascript
// @flowimport * as AbsintheSocket from "@jumpn/absinthe-phoenix-socket";
import {createAbsintheSocketLink} from "@jumpn/absinthe-phoenix-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
// @flowimport 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
// @flowimport ApolloClient from "apollo-client";
import {ApolloLink} from "apollo-link";
import {createHttpLink} from "apollo-link-http";
import {hasSubscription} from "@jumpn/utils-graphql";
import {InMemoryCache} from "apollo-cache-inmemory";// see example 1
import absintheSocketLink from "./absinthe-socket-link";const link = new ApolloLink.split(
operation => hasSubscription(operation.query),
absintheSocketLink,
createHttpLink({uri: "/graphql"})
);const client = new ApolloClient({
link,
cache: new InMemoryCache()
});
```## API
### createAbsintheSocketLink
Creates a terminating ApolloLink to request operations using given
AbsintheSocket instance**Parameters**
- `absintheSocket` **AbsintheSocket**
- `onError` **$PropertyType<Observer<any>, `"onError"`>**
- `onStart` **$PropertyType<Observer<any>, `"onStart"`>**## References
- [Absinthe Phoenix Socket](https://github.com/jumpn/absinthe-phoenix-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** / Mauro Titimoli ([email protected])