Controllers: ApolloController
ApolloController
is the abstract base class at the heart of Apollo Elements. You should not import ApolloController
directly, instead use the subclasses: ApolloQueryController
, ApolloMutationController
, and ApolloSubscriptionController
.
Properties
variables
Variables<D, V> | null
Variables for the operation.
options
ApolloControllerOptions<D, V>
Options for the operation and controller.
Option | Type | Description |
---|---|---|
client | ApolloClient<NormalizedCacheObject> |
The ApolloClient instance for the controller. |
variables | Variables<D, V> |
Variables for the operation. |
context | any |
Context passed to the link execution chain. |
errorPolicy | ErrorPolicy |
the error policy for the operation |
hostElement | HTMLElement |
When provided, the controller will fall back to this element to fire events |
loading
boolean
Whether a request is in-flight.
errors
readonly GraphQLError[]
Latest errors from the operation, or []
.
error
ApolloError | null
Latest error from the operation, or null
.
document
ComponentDocument<D, V> | null
The GraphQL document for the operation.
data
Data<D> | null
Latest data for the operation, or null
.
client
ApolloClient<NormalizedCacheObject> | null
The ApolloClient
instance for this controller.
called
boolean
Methods
hostDisconnected
Returns
void
hostConnected
Returns
void
Events
Name | Type | Description |
---|---|---|
apollo-controller-disconnected |
|
The controller's host disconnected from the DOM. |
apollo-controller-connected |
|
The controller's host connected to the DOM. |
Private API
Private Properties
emitter
EventTarget
The event emitter to use when firing events, usually the host element.
#options
ApolloControllerOptions<D, V>
Option | Type | Description |
---|---|---|
client | ApolloClient<NormalizedCacheObject> |
The ApolloClient instance for the controller. |
variables | Variables<D, V> |
Variables for the operation. |
context | any |
Context passed to the link execution chain. |
errorPolicy | ErrorPolicy |
the error policy for the operation |
hostElement | HTMLElement |
When provided, the controller will fall back to this element to fire events |
#document
ComponentDocument<D, V> | null
#client
ApolloClient<NormalizedCacheObject> | null
Private Methods
variablesChanged
callback for when the GraphQL variables change.
Parameters
variables
Variables<D, V> | null
Returns
void
optionsChanged
callback for when the options change.
Parameters
options
ApolloControllerOptions<D, V>
Option | Type | Description |
---|---|---|
client | ApolloClient<NormalizedCacheObject> |
The ApolloClient instance for the controller. |
variables | Variables<D, V> |
Variables for the operation. |
context | any |
Context passed to the link execution chain. |
errorPolicy | ErrorPolicy |
the error policy for the operation |
hostElement | HTMLElement |
When provided, the controller will fall back to this element to fire events |
Returns
void
notify
requests an update on the host with the provided properties.
Parameters
properties
Record<string, unknown>
Returns
void
init
Assigns the controller's variables and GraphQL document.
Parameters
document
ComponentDocument<D, V> | null
Returns
void
documentChanged
callback for when the GraphQL document changes.
Parameters
document
ComponentDocument<D, V> | null
Returns
void
clientChanged
callback for when the Apollo client changes.
Parameters
client
ApolloClient<NormalizedCacheObject> | null
Returns
void
Exports
import { ApolloController } from '@apollo-elements/core/apollo-controller';