Gluon: ApolloSubscription
ApolloSubscription
inherits from ApolloElement
and implements the ApolloSubscriptionInterface
.
Read the subscription component guides for examples and tips.
Exports
import { ApolloSubscription } from '@apollo-elements/fast/apollo-subscription';
Properties
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.
fetchPolicy
inherited from ApolloSubscriptionInterfaceFetchPolicy
Specifies the FetchPolicy to be used for this subscription.
loading
inherited from ApolloElementInterfaceboolean
Whether a request is in-flight.
noAutoSubscribe
inherited from ApolloSubscriptionInterface no-auto-subscribeboolean
If true, the element will not begin querying data until you manually call subscribe
notifyOnNetworkStatusChange
inherited from ApolloSubscriptionInterfaceboolean
Whether or not updates to the network status should trigger next on the observer of this subscription.
observable
(optional) inherited from ApolloSubscriptionInterfaceObservable<FetchResult<Data<D>>>
Observable watching this element's subscription.
observableSubscription
inherited from ApolloSubscriptionInterfaceZenObservable.Subscription
Subscription to the observable
pollInterval
(optional) inherited from ApolloSubscriptionInterfacenumber
The time interval (in milliseconds) on which this subscription should be refetched from the server.
shouldResubscribe
inherited from ApolloSubscriptionInterfaceboolean | ((options: SubscriptionDataOptions<D, V>) => boolean)
Determines if your subscription should be unsubscribed and subscribed again.
skip
inherited from ApolloSubscriptionInterfaceboolean
If skip is true, the query will be skipped entirely
subscription
inherited from ApolloSubscriptionInterfaceDocumentNode | 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>
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
inherited from ApolloSubscriptionInterfaceCancels and clears the subscription
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
onError
(optional) inherited from ApolloSubscriptionInterfaceCallback for when an error occurs.
Parameters
error
Error
Returns
void
onSubscriptionComplete
(optional) inherited from ApolloSubscriptionInterfaceCallback for when subscription completes.
Returns
void
onSubscriptionData
(optional) inherited from ApolloSubscriptionInterfaceCallback for when subscription data updates.
Parameters
data
Data<D>
Returns
void
shouldSubscribe
inherited from ApolloSubscriptionInterfaceDetermines 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
inherited from ApolloSubscriptionInterfaceResets 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
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 |