apollo-link-ddp

3.0.0 • Public • Published

Apollo Link using DDP

This is the client part of the DDP setup for Apollo. It works out of the box in a Meteor environment but is also usable with packages like asteroid.

Installation

meteor npm install --save apollo-link-ddp apollo-link graphql

Setup

This packages gives you a DDPLink for your Apollo Client. Creating an Apollo Client is the same as with any other Apollo Link.

import ApolloClient from 'apollo-client';
import { DDPLink } from 'apollo-link-ddp';
import { InMemoryCache } from 'apollo-cache-inmemory';

export const client = new ApolloClient ({
  link: new DDPLink(),
  cache: new InMemoryCache()
});

Options

  • connection: The DDP connection to use. Default Meteor.connection.
  • method: The name of the method. Default __graphql.
  • publication: The name of the publication. Default __graphql-subscriptions.
  • ddpRetry: Retry failed DDP method calls. Default true. Switch off and use apollo-link-retry for more control.
  • socket: Optionally pass a socket to listen to for messages. This makes it easy to integrate with non-Meteor DDP clients.
// Pass options to the DDPLink constructor
new DDPLink({
  connection: Meteor.connection
});

Setup with Asteroid

const Asteroid = createClass();
const asteroid = new Asteroid({
    endpoint: 'ws://localhost:3000/websocket',
});

const link = new DDPLink({
    connection: asteroid,
    socket: asteroid.ddp.socket,
    subscriptionIdKey: 'id',
});

Setup with SimpleDDP

DDP-Apollo works with SimpleDDP version 2 and up.

const SimpleDDP = require('simpleddp');

const connection = new SimpleDDP({
    endpoint: 'ws://localhost:3000/websocket',
    SocketConstructor: global.WebSocket,
});

this.link = new DDPLink({
    connection: connection,
    socket: connection.ddpConnection.socket,
});

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i apollo-link-ddp

    Weekly Downloads

    84

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    46.5 kB

    Total Files

    30

    Last publish

    Collaborators

    • jamiter