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

called

boolean

data

Data<D> | null
Latest data for the operation, or null.

error

Error | null
Latest error from the operation, or null.

errors

readonly GraphQLError[]
Latest errors from the operation, or [].

loading

boolean
Whether a request is in-flight.

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

client

ApolloClient | null
The ApolloClient instance for this controller.

document

ComponentDocument<D, V> | null
The GraphQL document for the operation.

variables

Variables<D, V> | null
Variables for the operation.

Methods

hostConnected

Returns

void

hostDisconnected

Returns

void

Events

apollo-controller-connected

ApolloControllerConnectedEvent
The controller’s host connected to the DOM.

apollo-controller-disconnected

ApolloControllerDisconnectedEvent
The controller’s host disconnected from the DOM.

Private Properties

#options

private
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

#client

private
ApolloClient | null

#document

private
ComponentDocument<D, V> | null

emitter

protected
EventTarget
The event emitter to use when firing events, usually the host element.

Private Methods

notify

protectedrequests an update on the host with the provided properties.

Parameters

properties

Record<string, unknown>

Returns

void

documentChanged

protectedcallback for when the GraphQL document changes.

Parameters

document

ComponentDocument<D, V> | null

Returns

void

variablesChanged

protectedcallback for when the GraphQL variables change.

Parameters

variables

Variables<D, V> | null

Returns

void

clientChanged

protectedcallback for when the Apollo client changes.

Parameters

client

ApolloClient | null

Returns

void

optionsChanged

protectedcallback 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

init

protectedAssigns the controller’s variables and GraphQL document.

Parameters

document

ComponentDocument<D, V> | null

Returns

void

Exports

js ApolloController from apollo-controller.js