This package has been deprecated

Author message:

This package has moved to graphql-ws.

graphql-subscriptions-ws
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

graphql-subscriptions-ws

Work in progress!

A client for GraphQL subscriptions over WebSocket. Server implementation coming soon!

Getting started

yarn add subscriptions-transport-ws
# or
npm install subscriptions-transport-ws

Relay

import { createClient } from 'graphql-subscriptions-ws';
import { Network } from 'relay-runtime';

const subscriptionsClient = createClient({
  url: 'wss://some.url/graphql',
  connectionParams: () => {
    const session = getSession();
    if (!session) {
      return null;
    }
    return {
      Authorization: `Bearer ${session.token}`,
    };
  },
});

export const network = Network.create(
  // fetch
  (operation, variables, cacheConfig) => {
    return Observable.create((sink) => {
      fetchQuery(operation, variables, cacheConfig, sink);
    });
  },
  // subscribe
  (operation, variables) => {
    return Observable.create((sink) => {
      if (!operation.text) {
        return sink.error(new Error('Operation text cannot be empty'));
      }
      return subscriptionsClient.subscribe(
        {
          operationName: operation.name,
          query: operation.text,
          variables,
        },
        sink
      );
    });
  }
);

Protocol

Read more about it in the PROTOCOL.md

Want to help?

Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing.

Readme

Keywords

none

Package Sidebar

Install

npm i graphql-subscriptions-ws

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

17.7 kB

Total Files

7

Last publish

Collaborators

  • enisdenjo