Relay subscription helpers for GraphQL.js
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
test
.babelrc
.eslintrc
.gitignore
.travis.yml
LICENSE
README.md
codecov.yml
package.json
yarn.lock

README.md

graphql-relay-subscription Travis npm

Relay subscription helper for GraphQL.js.

Codecov Discord

Usage

As with mutationWithClientId in graphql-relay-js, subscriptionWithClientId creates subscriptions with single inputs and client subscription IDs.

import { parse, subscribe } from 'graphql';
import { subscriptionWithClientId } from 'graphql-relay-subscription';

/* ... */

const UpdateWidgetSubscription = subscriptionWithClientId({
  name: 'UpdateWidgetSubscription',
  inputFields: {
    widgetId: { type: GraphQLString },
  },
  outputFields: {
    widget: Widget,
  },
  subscribe: ({ widgetId }) => (
    createSubscription(`widgets:${widgetId}:updated`)
  ),
});

const subscription = await subscribe(
  schema,
  parse(`
    subscription ($input_0: UpdateWidgetSubscriptionInput!) {
      updateWidget(input: $input_0) {
        widget {
          name
        }
        clientSubscriptionId
      }
    }
  `),
  null,
  null,
  {
    input_0: {
      widgetId: 'foo',
      clientSubscriptionId: '0',
    },
  },
);