Skip to content
Interface for creating asynchronous links.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src (Fix) Bump package dependencies and fix imports Aug 15, 2018
.gitignore Initial commit Feb 14, 2018
.npmignore Initial commit Feb 14, 2018
README.md
package.json 0.1.1 Aug 15, 2018
rollup.config.js Fix build and deployment Feb 14, 2018
tsconfig.json Initial commit Feb 14, 2018
tslint.json Initial commit Feb 14, 2018

README.md

Defer Link

Purpose

An Apollo Link to allow links to asynchronously be prepared, even after the ApolloClient has been constructed.

Installation

npm install apollo-link-defer --save

Usage

import { WebSocketLink } from 'apollo-link-ws'
import { SubscriptionClient } from 'subscriptions-transport-ws'
import { deferLink } from "apollo-link-defer";

const deferredSubscriptionLink =
  Promise.resolve('/api/v1/eventbus')
    .then(path => api.get(path))
    .then(({ uri, address }) => {
      const token = cookie.get()
      return new SubscriptionClient(
        `${uri}/bridge?token=${token}&play_uri=${API_SERVER}`,
        { reconnect: true, connectionParams: { type: 'register', address } },
        SockJS
      )
    })
    .then(client => new WebSocketLink(client))

// This prevents the underlying link from being created until we have the correct URL.
const wsLink = deferLink(resolveSubscriptionLink)

// The client can still be built while we wait for the link to finish setting up.
// It will transparently be used once the link is successfully instantiated.
const client = new ApolloClient({link: wsLink})
You can’t perform that action at this time.