Apollo Elements Guides API Blog

Haunted: useSubscription

Apollo useSubscription hook for web components. Elements that call useSubscription inherit the ApolloSubscriptionInterface.

Read the subscription component guides for examples and tips.

Exports

import { useSubscription } from '@apollo-elements/haunted/useSubscription';

useSubscription

Apollo Subscription Hook for Web Components

Parameters

subscription

TypedDocumentNode|DocumentNode

GraphQL subscription document node

options

SubscriptionHookOptions<D, V> | undefined

Options to customize the content and behavior of the subscription

Option Description
client
ApolloClient
fetchPolicy
FetchPolicy
noAutoSubscribe
boolean
onSubscriptionComplete Callback that fires when the subscription ends. See onSubscriptionComplete
onSubscriptionData Callback for when subscription produces new data. See onSubscriptionData
shouldResubscribe
boolean
shouldSubscribe Predicate which determines whether to automatically subscribe. See shouldSubscribe
skip
boolean
subscription
DocumentNode | TypedDocumentNode
variables
Variables<D, V> 

Returns

SubscriptionResult<D>

Latest data, error, and loading state of the subscription

Property Type Description
data
Data<D>
Latest subscription data.
error
ApolloError
Latest subscription error.
loading
boolean
Whether a request is in-flight.