Absinthe Phoenix Socket Relay
Using npm
$ npm install --save @jumpn/absinthe-phoenix-socket-apollo-link
Using yarn
$ yarn add @jumpn/absinthe-phoenix-socket-apollo-link
- Create AbsintheSocketLink (
absinthe-socket-link.js
)
// @flow
import * 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")
));
- Send all the operations using AbsintheSocketLink
// @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()
});
- Subscribe using AbsintheSocketLink and send queries and mutations using HttpLink
// @flow
import 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()
});
Creates a terminating ApolloLink to request operations using given AbsintheSocket instance
Parameters
absintheSocket
AbsintheSocketonError
$PropertyType<Observer<any>,"onError"
>onStart
$PropertyType<Observer<any>,"onStart"
>
- Absinthe Phoenix Socket
- Apollo Link
MIT ©️ Jumpn Limited / Mauro Titimoli (mauro@jumpn.com)