Components: apollo-subscription
<apollo-subscription>
lets you query GraphQL without writing any JavaScript. Import the custom element then write your template, query, and variables in HTML. The element class inherits from ApolloSubscriptionInterface
This page has detailed API documentation for <apollo-subscription>
. See the <apollo-subscription>
HTML Element guide for a HOW-TO guide.
Live Demo
<apollo-subscription>
<script type="application/graphql">
subscription NewMessages {
newMessage {
id
message
author {
id
name
picture
}
}
}
</script>
<template>
<small><em>This demo is blocked by an <a target="_blank" rel="nofollow noreferer" href="https://github.com/apollographql/apollo-feature-requests/issues/299">issue in <code>SchemaLink</code></a>.</small>
<sl-alert type="primary" duration="3000" closable open>
<sl-icon slot="icon" name="info-circle"></sl-icon>
<article>
<img src="{{ data.newMessage.author.picture }}"
alt="{{ data.newMessage.author.name }}"
title="{{ data.newMessage.author.name }}"/>
<span>{{ data.newMessage.message }}</span>
</article>
</sl-alert>
</template>
</apollo-subscription>
Render a GraphQL subscription to the DOM
Examples
Attributes
'no-shadow'
inherited from StampinoRenderBoolean|string
When set, the element will render to a <div>
in its light DOM. If set with a string, the string will be the div's class name.
Properties
is
(read-only)string
subscription
null | ComponentDocument<D, V>
A GraphQL document containing a single subscription.
skip
skipboolean
If true, the query will be skipped entirely
shouldResubscribe
should-resubscribeboolean
Determines if your subscription should be unsubscribed and subscribed again.
pollInterval
poll-intervalnumber | undefined
The time interval (in milliseconds) on which this subscription should be refetched from the server.
notifyOnNetworkStatusChange
notify-on-network-status-changeboolean
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-policythis['controller']['options']['fetchPolicy'] | undefined
Specifies the FetchPolicy to be used for this subscription.
errorPolicy
error-policythis['controller']['options']['errorPolicy'] | undefined
Error policy for the subscription
context
Record<string, any> | undefined
Context passed to the link execution chain.
canAutoSubscribe
(read-only)boolean
Flags an element that's ready and able to auto subscribe
client
inherited from ApolloElementApolloClient<NormalizedCacheObject> | null
The Apollo Client instance.
controller
inherited from ApolloElementApolloController<D, V>
data
inherited from ApolloElementData<D> | null
Latest Data.
document
inherited from ApolloElementComponentDocument<D, V> | null
Operation document.
GraphQL operation document i.e. query, subscription, or mutation.
Must be a parsed GraphQL DocumentNode
error
inherited from ApolloElementError | ApolloError | null
Latest error
errors
inherited from ApolloElementreadonly GraphQLError[]
Latest errors
loading
inherited from ApolloElement loadingboolean
Whether a request is in flight.
readyToReceiveDocument
inherited from ApolloElementboolean
template
(read-only) inherited from StampinoRender templateHTMLTemplateElement | null
Template element to render. Can either be a light-DOM child of the element,
or referenced by ID with the template
attribute.
templateHandlers
inherited from StampinoRenderTemplateHandlers
variables
inherited from ApolloElementVariables<D, V> | null
Operation variables.
Methods
subscribe
Resets the observable and subscribes.
Parameters
args
Parameters<this['controller']['subscribe']>
Returns
void
shouldSubscribe
Parameters
options
Partial<this['controller']['options']>
Returns
boolean
cancel
Cancels and clears the subscription
Returns
void
$
inherited from StampinoRenderquerySelector
within the render root.
Parameters
sel
string
Returns
E | null
$$
inherited from StampinoRenderquerySelectorAll
within the render root.
Parameters
sel
string
Returns
NodeListOf<E>
Private API
Private Methods
isQueryable
inherited from StampinoRenderParameters
node
Node
Returns
node is (ShadowRoot|Document)
createRenderRoot
inherited from StampinoRenderReturns
ShadowRoot|HTMLElement
getElementByIdFromRoot
inherited from StampinoRenderParameters
id
string|null
Returns
HTMLElement | null
getTemplateFromRoot
inherited from StampinoRenderReturns
HTMLTemplateElement | null
Exports
import '@apollo-elements/components/apollo-subscription';
import { ApolloSubscriptionElement } from '@apollo-elements/components/apollo-subscription';