Apollo Elements Apollo Elements Guides API Blog Toggle darkmode

Hybrids: Subscription Factory

Use the subscription factory to add a GraphQL subscription to you hybrids element.

import { subscription, define, html } from '@apollo-elements/hybrids';

import { UserAddedSubscription } from './UserAdded.subscription.graphql.js';

import '@material/mwc-snackbar';

define('user-added', {
  userAdded: subscription(UserAddedSubscription),
  opened: false,
  render: host => html`
    <link rel="stylesheet" href="user-added.css">
    <mwc-snackbar
        labeltext="${host.userAdded.data?.name} Joined!"
        open="${host.last !== host.userAdded.data?.name}"
        onMDCSnackbar:closed="${() => host.opened = false}"
        onMDCSnackbar:opened="${() => {
          host.opened = true;
          host.last = host.userAdded.data?.name;
        }}"
    ></mwc-snackbar>
  `,
});

subscription

Parameters

subscriptionDocument

ComponentDocument<D> | null

The subscription document.

options

ApolloSubscriptionControllerOptions<D, V>

Options to control the subscription.

Returns


Exports

import { subscription } from '@apollo-elements/hybrids/factories/subscription';