Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PolymerApolloQuery<TData, TVariables>

element

apollo-query

<apollo-query> fires Polymer-style prop-changed events when its data, error, loading or networkStatus properties change.

example
<apollo-query data="{{data}}" variables="<a href="_apollo_elements_polymer.polymerapolloquery.html#variables">variables</a>">
  <script type="application/graphql">
    query User($id: ID!) {
      user(id: $id) {
        name
        picture
      }
    }
  </script>
</apollo-query>

<paper-icon-item>
  <iron-image slot="item-icon">[[data.user.picture]]</iron-image>
  [[data.user.name]]
</paper-icon-item>
fires

'apollo-element-disconnected' when the element disconnects from the dom

fires

'apollo-element-connected' when the element connects to the dom

fires

'data-changed'

fires

'error-changed'

fires

'errors-changed'

fires

'loading-changed'

fires

'network-status-changed'

Type parameters

  • TData

  • TVariables

Hierarchy

Implements

Index

Constructors

constructor

Properties

Private __document

__document: DocumentNode = null

Private __mo

Private __options

__options: Partial<WatchQueryOptions> = null

Private __variables

__variables: TVariables = null

client

client: ApolloClient<NormalizedCacheObject> = window.__APOLLO_CLIENT__

Optional context

context: Record<string, unknown>

data

data: TData

error

errorPolicy

errorPolicy: ErrorPolicy = "none"

errors

errors: readonly GraphQLError[]

fetchPolicy

fetchPolicy: FetchPolicy

loading

loading: boolean

networkStatus

networkStatus: NetworkStatus = NetworkStatus.ready

nextFetchPolicy

nextFetchPolicy: FetchPolicy

noAutoSubscribe

noAutoSubscribe: boolean

notifyOnNetworkStatusChange

notifyOnNetworkStatusChange: boolean

observableQuery

observableQuery: ObservableQuery

options

options: Partial<WatchQueryOptions>

partial

partial: boolean

partialRefetch

partialRefetch: boolean

pollInterval

pollInterval: number

query

returnPartialData

returnPartialData: boolean

variables

variables: TVariables

Accessors

document

Methods

Optional adoptedCallback

  • adoptedCallback(): 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>): boolean
  • Determines whether the element is able to automatically subscribe

    Parameters

    • Optional options: Partial<SubscriptionOptions>

    Returns boolean

Protected connectedCallback

  • connectedCallback(): void

disconnectedCallback

  • disconnectedCallback(): void

executeQuery

  • executeQuery(params?: Partial<QueryOptions<TVariables>>): Promise<void | ApolloQueryResult<TData>>
  • Executes a Query once and updates the component with the result

    Parameters

    • Optional params: Partial<QueryOptions<TVariables>>

    Returns Promise<void | ApolloQueryResult<TData>>

fetchMore

  • fetchMore(params?: Partial<FetchMoreQueryOptions<TVariables, keyof TVariables> & FetchMoreOptions<TData, TVariables>>): Promise<ApolloQueryResult<TData>>
  • 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<TVariables, keyof TVariables> & FetchMoreOptions<TData, TVariables>>

    Returns Promise<ApolloQueryResult<TData>>

Private nextData

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

    Parameters

    • Optional result: ApolloQueryResult<TData>

    Returns void

Private nextError

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

    Parameters

    Returns void

Optional onData

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

    • _result: ApolloQueryResult<TData>

    Returns void

Optional onError

  • onError(_error: Error): void
  • Parameters

    Returns void

refetch

  • refetch(variables: TVariables): Promise<ApolloQueryResult<TData>>
  • Exposes the ObservableQuery#refetch method.

    Parameters

    • variables: TVariables

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

    Returns Promise<ApolloQueryResult<TData>>

shouldSubscribe

  • shouldSubscribe(options?: Partial<SubscriptionOptions>): 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>

    Returns boolean

subscribe

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

    Parameters

    • Optional params: Partial<SubscriptionOptions>

    Returns Subscription

subscribeToMore

  • subscribeToMore(options: SubscribeToMoreOptions): () => 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

    Returns () => void

      • (): void
      • Returns void

watchQuery

  • watchQuery(params?: Partial<WatchQueryOptions>): ObservableQuery
  • 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>

    Returns ObservableQuery