Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ApolloQueryElement<D, V>

Type parameters

  • D

  • V

Hierarchy

  • ApolloQueryElement<D, V>
    • ApolloQueryElement

Implements

Index

Properties

Private __networkStatus

__networkStatus: NetworkStatus = NetworkStatus.ready

Private __options

__options: Partial<WatchQueryOptions> | null = null

Private _document

_document: DocumentNode | null = null

Private _documentSetByJS

_documentSetByJS: boolean = false

Private _variables

_variables: V | null = null

Private _variablesSetByJS

_variablesSetByJS: boolean = false

client

client: ApolloClient<NormalizedCacheObject> | null = window.__APOLLO_CLIENT__ ?? null

Optional context

context: Record<string, unknown>

data

data: D | null

error

error: Error | ApolloError | null

errorPolicy

errorPolicy: ErrorPolicy = "none"

errors

errors: readonly GraphQLError[] | null

Optional fetchPolicy

fetchPolicy: FetchPolicy

loading

loading: boolean

Private mo

mo: MutationObserver | null = null

networkStatus

networkStatus: NetworkStatus

Optional nextFetchPolicy

nextFetchPolicy: FetchPolicy

noAutoSubscribe

noAutoSubscribe: boolean

notifyOnNetworkStatusChange

notifyOnNetworkStatusChange: boolean

Optional observableQuery

observableQuery: ObservableQuery<D, V>

options

options: Partial<WatchQueryOptions<V, D>> | null

Optional partial

partial: undefined | false | true

Optional partialRefetch

partialRefetch: undefined | false | true

Optional pollInterval

pollInterval: undefined | number

query

query: DocumentNode | null

Optional returnPartialData

returnPartialData: undefined | false | true

variables

variables: V | null

Static documentType

documentType: string = "query"

Accessors

document

Methods

Optional adoptedCallback

  • adoptedCallback(): void
  • Called when the element is adopted to a document.

    Returns void

Optional attributeChangedCallback

  • attributeChangedCallback(name: string, oldValue: string, newValue: string): void
  • Called when one of the element's observedAttributes changes.

    Parameters

    • name: string

      name of the observed attribute

    • oldValue: string

      previous value of the attribute. null if it was nonexistent

    • newValue: string

      current value of the attribute. null if removed.

    Returns void

Protected canSubscribe

  • canSubscribe(options?: Partial<SubscriptionOptions<V, D>>): boolean
  • Determines whether the element is able to automatically subscribe

    Parameters

    • Optional options: Partial<SubscriptionOptions<V, D>>

    Returns boolean

Protected connectedCallback

  • connectedCallback(): void

disconnectedCallback

  • disconnectedCallback(): void

documentChanged

executeQuery

  • executeQuery(params?: Partial<QueryOptions<V>>): Promise<ApolloQueryResult<D>>
  • Executes a Query once and updates the component with the result

    Parameters

    • Optional params: Partial<QueryOptions<V>>

    Returns Promise<ApolloQueryResult<D>>

fetchMore

  • fetchMore(params?: Partial<FetchMoreQueryOptions<V, keyof V> & FetchMoreOptions<D, V>>): Promise<ApolloQueryResult<D>>
  • The optional updateQuery parameter is a function that takes the previous query data, then a { subscriptionData: TSubscriptionResult } object, and returns an object with updated query data based on the new results.

    The optional variables parameter is an optional new variables object.

    Parameters

    • Optional params: Partial<FetchMoreQueryOptions<V, keyof V> & FetchMoreOptions<D, V>>

    Returns Promise<ApolloQueryResult<D>>

Private getDOMGraphQLDocument

Private getDOMVariables

  • getDOMVariables(): V | null
  • Gets operation variables from the element's JSON script child

    Returns V | null

Private nextData

  • nextData(result: ApolloQueryResult<D>): void
  • Sets data, loading, and error on the instance when new subscription results arrive.

    Parameters

    • result: ApolloQueryResult<D>

    Returns void

Private nextError

  • Sets error and loading on the instance when the subscription errors.

    Parameters

    Returns void

Private onDOMMutation

  • onDOMMutation(records: MutationRecord[]): void

Optional onData

  • onData(_result: ApolloQueryResult<D>): void
  • Parameters

    • _result: ApolloQueryResult<D>

    Returns void

Optional onError

  • onError(_error: Error): void

refetch

  • refetch(variables: V): Promise<ApolloQueryResult<D>> | void
  • Exposes the ObservableQuery#refetch method.

    Parameters

    • variables: V

      The new set of variables. If there are missing variables, the previous values of those variables will be used..

    Returns Promise<ApolloQueryResult<D>> | void

shouldSubscribe

  • shouldSubscribe(options?: Partial<SubscriptionOptions<V, D>>): boolean
  • Determines whether the element should attempt to automatically subscribe i.e. begin querying

    Override to prevent subscribing unless your conditions are met.

    Parameters

    • Optional options: Partial<SubscriptionOptions<V, D>>

    Returns boolean

subscribe

  • subscribe(params?: Partial<SubscriptionOptions<V, D>>): Subscription
  • Resets the observableQuery and subscribes.

    Parameters

    • Optional params: Partial<SubscriptionOptions<V, D>>

    Returns Subscription

subscribeToMore

  • subscribeToMore(options: SubscribeToMoreOptions<D, V>): (() => void) | void
  • Lets you pass a GraphQL subscription and updateQuery function to subscribe to more updates for your query.

    The updateQuery parameter is a function that takes the previous query data, then a { subscriptionData: TSubscriptionResult } object, and returns an object with updated query data based on the new results.

    Parameters

    • options: SubscribeToMoreOptions<D, V>

    Returns (() => void) | void

variablesChanged

  • variablesChanged(variables: V): void

watchQuery

  • watchQuery(params?: Partial<WatchQueryOptions<V, D>>): ObservableQuery<D, V>
  • Creates an instance of ObservableQuery with the options provided by the element.

    • context Context to be passed to link execution chain
    • errorPolicy Specifies the ErrorPolicy to be used for this query
    • fetchPolicy Specifies the FetchPolicy to be used for this query
    • fetchResults Whether or not to fetch results
    • metadata Arbitrary metadata stored in the store with this query. Designed for debugging, developer tools, etc.
    • notifyOnNetworkStatusChange Whether or not updates to the network status should trigger next on the observer of this query
    • pollInterval The time interval (in milliseconds) on which this query should be refetched from the server.
    • query A GraphQL document that consists of a single query to be sent down to the server.
    • variables A map going from variable name to variable value, where the variables are used within the GraphQL query.

    Parameters

    • Optional params: Partial<WatchQueryOptions<V, D>>

    Returns ObservableQuery<D, V>