Skip to content
Branch: master
Find file History
mgtitimoli chore: Release
 - @absinthe/socket-apollo-link@0.2.1
 - @absinthe/socket-graphiql@0.2.1
 - @absinthe/socket-relay@0.2.1
 - @absinthe/socket@0.2.1
Latest commit e61a999 Feb 20, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src chore: Release candidate v0.2.0 Dec 13, 2018
.envrc feat(*): Initial commit Nov 6, 2017
.npmignore
.npmrc feat(*): Initial commit Nov 6, 2017
LICENSE.txt chore: Fix copyright holder Nov 10, 2017
README.md
indexIgnore.sed
package.json chore: Release Feb 20, 2019
readmeTemplate.ejs chore: Release candidate v0.2.0 Dec 13, 2018

README.md

@absinthe/socket-apollo-link

Absinthe Socket Apollo Link

Installation

Using npm

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

Using yarn

$ yarn add @absinthe/socket-apollo-link

Examples

  1. Create AbsintheSocketLink (absinthe-socket-link.js)
// @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")
));
  1. 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()
});
  1. Subscribe using AbsintheSocketLink and send queries and mutations using HttpLink
// @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

createAbsintheSocketLink

Creates a terminating ApolloLink to request operations using given AbsintheSocket instance

Parameters

  • absintheSocket AbsintheSocket
  • onError $ElementType<Observer<Result, Variables>, "onError">
  • onStart $ElementType<Observer<Result, Variables>, "onStart">

References

License

MIT ©️ Jumpn Limited.

You can’t perform that action at this time.