Interfaces: ApolloSubscription
Subscription components update in real time in reaction to events on your GraphQL server. They are ideal for uses like chat rooms or stock tickers.
Subscription components inherit the ApolloElementInterface.
Exports
import { ApolloSubscriptionInterface } from '@apollo-elements/interfaces/apollo-subscription';
Properties
fetchPolicy
FetchPolicy
Specifies the FetchPolicy to be used for this subscription.
noAutoSubscribe
no-auto-subscribeboolean
If true, the element will not begin querying data until you manually call subscribe
notifyOnNetworkStatusChange
boolean
Whether or not updates to the network status should trigger next on the observer of this subscription.
observable
(optional)Observable<FetchResult<Data<D>>>
Observable watching this element's subscription.
observableSubscription
ZenObservable.Subscription
Subscription to the observable
pollInterval
(optional)number
The time interval (in milliseconds) on which this subscription should be refetched from the server.
shouldResubscribe
boolean | ((options: SubscriptionDataOptions<D, V>) => boolean)
Determines if your subscription should be unsubscribed and subscribed again.
skip
boolean
If skip is true, the query will be skipped entirely
subscription
DocumentNode | TypedDocumentNode
A GraphQL document containing a single subscription. You can set it as a JavaScript property or by appending a GraphQL script to the element (light DOM).
<script type="application/graphql">
subscription { messages { text } }
</script>
client
inherited from ApolloElementInterfaceApolloClient<NormalizedCacheObject> | null
The Apollo Client instance
Defaults to window.__APOLLO_CLIENT__
, which is set by default when creating an Apollo Client. That means that in most cases, it's not necessary to explicity set the client
property. For more information see Getting Started: Apollo Client.
context
(optional) inherited from ApolloElementInterfaceRecord<string, unknown>
Context passed to the link execution chain.
data
inherited from ApolloElementInterfaceData<D> | null
Latest subscription data.
document
inherited from ApolloElementInterfaceDocumentNode | TypedDocumentNode | null
A GraphQL document containing a single query, mutation, or subscription. You can set it as a JavaScript property or by appending a GraphQL script to the element (light DOM).
documentType
inherited from ApolloElementInterface'subscription'
Hint that this is a subscription component
error
(optional) inherited from ApolloElementInterfaceError | ApolloError | null
Latest error
errors
(optional) inherited from ApolloElementInterfacereadonly GraphQLError[] | null
Latest errors.
loading
inherited from ApolloElementInterfaceboolean
Whether a request is in-flight.
variables
inherited from ApolloElementInterfaceVariables<D, V> | null
An object map from variable name to variable value, where the variables are used within the GraphQL subscription.
If the element has not yet subscribed and noAutoSubscribe
is not set, setting variables causes the element to subscribe, otherwise, setting variables causes the query to refetch.
Methods
cancel
Cancels and clears the subscription
Returns
void
onError
(optional)Callback for when an error occurs.
Parameters
error
Error
Returns
void
onSubscriptionComplete
(optional)Callback for when subscription completes.
Returns
void
onSubscriptionData
(optional)Callback for when subscription data updates.
Parameters
data
Data<D>
Returns
void
shouldSubscribe
Determines whether the element should attempt to subscribe i.e. begin querying Override to prevent subscribing unless your conditions are met
Parameters
options
Partial<SubscriptionOptions<Variables<D, V>, Data<D>>>
Property | Type | Description |
---|---|---|
query |
|
See query |
variables |
|
See variables |
fetchPolicy |
|
See fetchPolicy |
errorPolicy |
|
See errorPolicy |
context |
|
Context object passed through the link execution chain. |
Returns
boolean
subscribe
Resets the observable and subscribes.
Parameters
params
Partial<SubscriptionDataOptions<D, V>>
Options for controlling how the subscription subscribes.
Option | Type | Description |
---|---|---|
client |
|
Apollo Client to use for the subscription. |
fetchPolicy |
|
See fetchPolicy |
shouldResubscribe |
|
Boolean, or a predicate function of SubscriptionDataOptions that determines if your subscription should be unsubscribed and subscribed again |
skip |
|
If skip is true, the subscription will be skipped entirely. |
subscription |
|
GraphQL document with a single subscription. |
variables |
|
An object containing all of the variables your subscription needs to execute. |
Returns
void
documentChanged
(optional) inherited from ApolloElementInterfaceLifecycle callback that reacts to changes in the GraphQL document.
Parameters
document
DocumentNode | TypedDocumentNode | null
The GraphQL document.
Returns
void
variablesChanged
(optional) inherited from ApolloElementInterfaceLifecycle callback that reacts to changes in the operation variables.
Parameters
variables
Variables<D, V> | null
The variables.
Returns
void
Events
Name | Type | Description |
---|---|---|
apollo-element-connected |
|
when the element connects to the DOM |
apollo-element-disconnected |
|
when the element disconnects from the DOM |
apollo-error |
|
when the mutation rejects |
apollo-subscription-result |
|
when the subscription resolves |