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.
Common interface for subscription elements
See ApolloElementInterface for more information on events
Properties
documentType
static(read-only)'document'|'query'|'mutation'|'subscription'controller
publicApolloController<D, V>data
publicData<D> | nullvariables
publicVariables<D, V> | nullAn object map from variable name to variable value, where the variables are used within the GraphQL subscription.
Setting variables will initiate the subscription, unless noAutoSubscribe is also set.
subscription
publicComponentDocument<D, V> | nullcanAutoSubscribe
public(read-only)booleanfetchPolicy
publicstring | undefinedpollInterval
publicnumber | undefinednoAutoSubscribe
publicbooleansubscribeshouldResubscribe
publicboolean | ((options: SubscriptionDataOptions<Data<D>, Variables<D, V>>) => boolean)skip
publicbooleanclient
publicApolloClient | nulldocument
publicComponentDocument<D, V> | nullgraphql-tag.error
publicError | nullerrors
publicreadonly GraphQLError[]loading
publicbooleancontext
publicRecord<string, unknown> | undefinederrorPolicy
publicErrorPolicy | undefinedMuch like fetchPolicy, errorPolicy allows you to control how GraphQL errors
from the server are sent to your UI code. By default, the error policy treats any
GraphQL Errors as network errors and ends the request chain.
It doesn’t save any data in the cache, and renders your UI with the error property
set to an ApolloError. By changing this policy per request, you can adjust how
GraphQL Errors are managed by your UI. The possible options for errorPolicy are:
none(default): any errors from the request are treated like runtime errors and the observable is stopped (XXX this is default to lower breaking changes going from AC 1.0 => 2.0)ignore: errors from the request do not stop the observable, but also don’t callnextall: errors are treated like data and will notify observables
readyToReceiveDocument
publicbooleanMethods
onSubscriptionData
publicCallback for when data is updatedParameters
_result
OnSubscriptionDataParams<Data<D>>Returns
voidonSubscriptionComplete
publicCallback for when subscription completes.Returns
voidonError
publicCallback for when error is updatedParameters
error
ErrorReturns
voidsubscribe
publicResets the subscription and subscribes.Parameters
params
Partial<SubscriptionDataOptions<D, V>>| Option | Type | Description |
|---|---|---|
| client | ApolloClient |
Apollo Client to use for the subscription. |
| context | Record<string, unknown> |
Context object passed through the link execution chain. |
| errorPolicy | ErrorPolicy |
Error policy to use for the subscription. See errorPolicy |
| fetchPolicy | FetchPolicy |
See fetchPolicy |
| shouldResubscribe | boolean |
Boolean, or a predicate function of SubscriptionDataOptions that determines if your subscription should be unsubscribed and subscribed again |
| skip | boolean |
If skip is true, the subscription will be skipped entirely. |
| subscription | DocumentNode |
GraphQL document with a single subscription. |
| variables | Variables<D, V> |
An object containing all of the variables your subscription needs to execute. |
Returns
voidcancel
publicCancels and clears the subscriptionReturns
voidshouldSubscribe
publicDetermines whether the element should attempt to subscribe automatically Override to prevent subscribing unless your conditions are metParameters
options
Partial<SubscriptionOptions<Variables<D, V>, Data<D>>>| Property | Type | Description |
|---|---|---|
| query | DocumentNode |
See query |
| variables | Variables<D, V> |
See variables |
| fetchPolicy | FetchPolicy |
See fetchPolicy |
| errorPolicy | ErrorPolicy |
See errorPolicy |
| context | Record<string, unknown> |
Context object passed through the link execution chain. |
Returns
booleanEvents
apollo-subscription-result
ApolloSubscriptionResultEventThe subscription updatedapollo-error
CustomEvent<ApolloError>The subscription produced an errorapollo-element-connected
ApolloElementEventThe element connected to the DOMapollo-element-disconnected
ApolloElementEventThe element disconnected from the DOM
Private Methods
documentChanged
protectedLifecycle callback that reacts to changes in the GraphQL documentParameters
document
ComponentDocument<D, V> | nullReturns
voidvariablesChanged
protectedLifecycle callback that reacts to changes in the operation variablesParameters
variables
Variables<D, V> | nullReturns
voidExports
js CustomElement from types.js
js ControllerHost from types.js
js ApolloElementElement from types.js
js ApolloMutationElement from types.js
js ApolloQueryElement from types.js
js ApolloSubscriptionElement from types.js
js GraphQLError from types.js