Giter Site home page Giter Site logo

jumpn / absinthe-phoenix-socket-apollo-link Goto Github PK

View Code? Open in Web Editor NEW
2.0 5.0 0.0 70 KB

Absinthe Phoenix Socket Apollo Link

License: MIT License

JavaScript 55.59% HTML 44.41%
absinthe absinthe-phoenix absinthe-graphql graphql apollo apollo-client apollographql socket

absinthe-phoenix-socket-apollo-link's Introduction

@jumpn/absinthe-phoenix-socket-apollo-link

Absinthe Phoenix Socket Relay

Installation

Using npm

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

Using yarn

$ yarn add @jumpn/absinthe-phoenix-socket-apollo-link

Examples

  1. 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")
));
  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 {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

License

MIT Šī¸ Jumpn Limited / Mauro Titimoli ([email protected])

absinthe-phoenix-socket-apollo-link's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.