Skip to content
Interface for creating asynchronous links.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
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
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

Defer Link


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


npm install apollo-link-defer --save


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

const deferredSubscriptionLink =
    .then(path => api.get(path))
    .then(({ uri, address }) => {
      const token = cookie.get()
      return new SubscriptionClient(
        { reconnect: true, connectionParams: { type: 'register', address } },
    .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.