Apollo Elements Guides API Blog

Interfaces: ApolloElement

Common base interface for Apollo Elements. Elements take either one or two type parameters. A single parameter is either a TypedDocumentNode or the type of the operation's result, in which case the variables type defautls to OperationVariables, which is an object of arbitrary string keys and unknown values. If two parameters are used, the first is the result type, the second is the type of the operation variables.

Exports

import { ApolloElementInterface } from '@apollo-elements/interfaces/apollo-element';

Properties

client

ApolloClient<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)
Record<string, unknown>

Context passed to the link execution chain.

data

Data<D> | null

Latest data.

document

DocumentNode | TypedDocumentNode | null

Internal property corresponding to query, mutation, or subscription. Use those instead.

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). The document property should be considered internal and its use avoided.

static

documentType

'document'|'query'|'mutation'|'subscription'

Hint about what kind of component this is

error

(optional)
Error | ApolloError | null

Latest error

errors

(optional)
readonly GraphQLError[] | null

Latest errors.

loading

boolean

Whether a request is in-flight.

variables

Variables<D, V> | null

An object that maps from the name of a variable as used in the operation's GraphQL document to that variable's value.

Methods

protected

documentChanged

(optional)

Lifecycle callback that reacts to changes in the GraphQL document.

Parameters

document

DocumentNode | TypedDocumentNode | null

The GraphQL document.

Returns

void
protected

variablesChanged

(optional)

Lifecycle 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
CustomEvent<ApolloElement>

when the element connects to the DOM

apollo-element-disconnected
CustomEvent<ApolloElement>

when the element disconnects from the DOM