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.
Common interface for subscription elements
See ApolloElementInterface
for more information on events
Properties
documentType
(read-only)'subscription'
variables
Variables<D, V> | null
Subscription variables.
An 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
ComponentDocument<D> | null
A GraphQL document containing a single subscription.
skip
boolean
If true, the query will be skipped entirely
shouldResubscribe
SubscriptionDataOptions['shouldResubscribe']
Determines if your subscription should be unsubscribed and subscribed again.
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 | TypedDocumentNode`{lang=ts} |
variables | Variables<D, V> |
An object containing all of the variables your subscription needs to execute. |
pollInterval
number
The time interval (in milliseconds) on which this subscription should be refetched from the server.
onSubscriptionData
ApolloMutationInterface<D, V>['onSubscriptionData']
Callback for when data is updated
onSubscriptionComplete
ApolloMutationInterface<D, V>['onSubscriptionComplete']
Callback for when subscription completes.
onError
ApolloMutationInterface<D, V>['onError']
Callback for when error is updated
notifyOnNetworkStatusChange
boolean
Whether or not updates to the network status should trigger next on the observer of this subscription.
noAutoSubscribe
no-auto-subscribeboolean
If true, the element will not begin querying data until you manually call subscribe
fetchPolicy
fetch-policyFetchPolicy
Specifies the FetchPolicy to be used for this subscription.
data
Data<D> | null
Latest subscription data.
controller
ApolloSubscriptionController<D, V>
canAutoSubscribe
boolean
Flags an element that's ready and able to auto subscribe
client
inherited from ApolloElementElementApolloClient<NormalizedCacheObject> | null
The Apollo Client instance.
context
inherited from ApolloElementElementRecord<string, unknown>
Context passed to the link execution chain.
document
inherited from ApolloElementElementComponentDocument<D> | null
Operation document.
GraphQL operation document i.e. query, subscription, or mutation.
Must be a parsed GraphQL DocumentNode, so use graphql-tag
.
error
inherited from ApolloElementElementError | ApolloError | null
Latest error
errorPolicy
inherited from ApolloElementElement error-policyErrorPolicy
Error Policy for the operation.
Much 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 callnext
all
: errors are treated like data and will notify observables
errors
inherited from ApolloElementElementreadonly GraphQLError[]
Latest errors
loading
inherited from ApolloElementElementboolean
Whether a request is in flight.
readyToReceiveDocument
inherited from ApolloElementElementboolean
True when the element is connected and ready to receive its GraphQL document
updateComplete
inherited from ApolloElementElementPromise<boolean>
Methods
subscribe
Resets 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 | TypedDocumentNode`{lang=ts} |
variables | Variables<D, V> |
An object containing all of the variables your subscription needs to execute. |
Returns
void
shouldSubscribe
Determines whether the element should attempt to subscribe automatically Override to prevent subscribing unless your conditions are met
Parameters
options
Partial<SubscriptionOptions<Variables<D, V>, Data<D>>>
Property | Type | Description |
---|---|---|
query | `DocumentNode | TypedDocumentNode`{lang=ts} |
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
boolean
cancel
Cancels and clears the subscription
Returns
void
addController
inherited from ApolloElementElementParameters
controller
ReactiveController
Returns
void
removeController
inherited from ApolloElementElementParameters
controller
ReactiveController
Returns
void
requestUpdate
inherited from ApolloElementElementParameters
name
string
value
unknown
Returns
void
Events
Name | Type | Description |
---|---|---|
apollo-subscription-result |
|
when the subscription updates |
apollo-error |
|
when the query rejects |
'apollo-element-connected' |
|
when the element connects to the dom |
'apollo-element-disconnected' |
|
when the element disconnects from the dom |
Private API
Private Methods
documentChanged
inherited from ApolloElementElementLifecycle callback that reacts to changes in the GraphQL document
Parameters
document
ComponentDocument<D> | null
Returns
void
update
inherited from ApolloElementElementParameters
args
any[]
Returns
void
updated
inherited from ApolloElementElementParameters
args
any[]
Returns
void
variablesChanged
inherited from ApolloElementElementLifecycle callback that reacts to changes in the operation variables
Parameters
variables
Variables<D, V> | null
Returns
void
Exports
import {
CustomElement,
ControllerHost, ApolloElementElement, ApolloMutationElement, ApolloQueryElement, ApolloSubscriptionElement} from '@apollo-elements/core/types';