• Docs
  • Pricing
  • Support
  • Blog
  • Login

›Subscriptions

Intro

  • What's OneGraph?
  • How does it work?
  • Creating your first app
  • Making your first query
  • OneGraphiQL
  • Authentication & Security Overview
  • Custom Google Auth

On the frontend

  • Using with Apollo
  • Log in to services
  • Example with create-react-app

External Authentication

  • What are JWTs?
  • AuthGuardian
  • Securing your Apollo server
  • Securing your Hasura API
  • Securing your Netlify site
  • Securing your express.js app
  • Advanced JWT customization with webhooks

Subscriptions

  • Subscriptions
  • Webhook-based subscriptions
  • Websocket-based subscriptions
  • Salesforce subscriptions
  • GitHub subscriptions
  • Gmail Subscriptions

Advanced

  • Persisted Queries
  • Mailchimp Signup with Persisted Queries

Websocket-based subscriptions

OneGraph supports websocket-based subscriptions for client-side apps.

Our websocket subscriptions follow the GraphQL over WebSocket Protocol.

OneGraph maintains a onegraph-subscription-client node package that works with onegraph-auth.

Installation

With yarn:

yarn add onegraph-subscription-client

With npm:

npm install --save onegraph-subscription-client

Usage

import {SubscriptionClient} from 'onegraph-subscription-client';

const ONEGRAPH_APP_ID = 'YOUR_APP_ID';

const client = new SubscriptionClient(ONEGRAPH_APP_ID);

client
  .request({
    query: /* GraphQL */ `
      subscription NpmPackagesSubscription {
        npm {
          allPublishActivity {
            package {
              name
            }
          }
        }
      }
    `,
    operationName: 'NpmPackagesSubscription',
  })
  .subscribe(
    next => {
      const npmPackage = next.data.npm.allPublishActivity.package;
      console.log(npmPackage);
    },
    error => console.error(error),
    () => console.log('done'),
  );

With OneGraphAuth

import {SubscriptionClient} from 'onegraph-subscription-client';
import {OneGraphAuth} from 'onegraph-auth';

const ONEGRAPH_APP_ID = 'YOUR_APP_ID';

const auth = new OneGraphAuth(ONEGRAPH_APP_ID);

const client = new SubscriptionClient(ONEGRAPH_APP_ID, {oneGraphAuth: auth});

With Apollo Client

import {SubscriptionClient} from 'onegraph-subscription-client';
import {ApolloClient} from 'apollo-client';
import {InMemoryCache} from 'apollo-cache-inmemory';

const ONEGRAPH_APP_ID = 'YOUR_APP_ID';

const subscriptionClient = new SubscriptionClient(ONEGRAPH_APP_ID);

const apolloClient = new ApolloClient({
  link: subscriptionClient,
  cache: new InMemoryCache(),
});

The full API docs are available on GitHub.

← Webhook-based subscriptionsSalesforce subscriptions →
Links
OneGraph Overview Example projectsOneGraphiQL Explorer
Support
Live chat on Spectrum> TwitterBlog
More
Terms of ServicePrivacy Policy
Copyright © 2020 OneGraph