Skip to content

ApolloQuery ​

Props ​

NameTypeDefaultDescription
query (required)TypedDocumentNode<TData, TVariables> The query document.
variablesTVariables | undefined Variables for the query.
disabledboolean | undefinedfalseSkip execution until a condition is met.
fetchPolicyuseQuery.Options<TData, TVariables>["fetchPolicy"] | undefined How the query reads from and writes to the cache.
pollIntervalnumber | undefined Refetch every N milliseconds.
debouncenumber | undefined Delay variable updates (ms). loading covers the window.
throttlenumber | undefined Throttle variable updates (ms). loading covers the window.
keepPreviousResultboolean | undefined Keep the previous result on screen while new variables are in flight.

Off by default, as in useQuery. Opt in for search and pagination, where clearing the list on every change flickers.
clientIdstring | undefined Name of the client to use, from the provided ApolloClients map.
empty((data: TData) => boolean) | undefined Decides whether a result counts as empty, selecting the #empty slot.

Without it #empty is never used, so #data handles the empty case itself.
optionsuseQuery.Options<TData, TVariables> | undefined Escape hatch for any other useQuery option.

Events ​

NamePayload
result[data: TData]
completeResult[data: TData]
partialResult[data: TData]
streamingResult[data: TData]
error[error: ErrorLike]
nextState[state: useQuery.Current<TData, "empty" | "complete" | "streaming" | "partial">]

Slots ​

#data ​

Opinionated mode. Providing this slot selects it, and data is never undefined.

Slot propType
dataTData
errorErrorLike | undefined
isPreviousResultboolean
loadingboolean
pendingboolean
refetch(variables?: TVariables | undefined) => Promise<RenameKey<ApolloClient.QueryResult<TData>, "data", "result"> | undefined>
fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(options: ObservableQuery.FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars>) => Promise<RenameKey<ApolloClient.QueryResult<TFetchData>, "data", "result">> | undefined

#loading ​

Shown while the first result is loading. Opinionated mode only.

No slot props.

#error ​

Shown when the query failed and there is nothing to display. Opinionated mode only.

Slot propType
errorErrorLike
refetch(variables?: TVariables | undefined) => Promise<RenameKey<ApolloClient.QueryResult<TData>, "data", "result"> | undefined>

#empty ​

Shown when the empty prop returns true, and as the last branch when the query settles with nothing to show. Without the empty prop, #data owns the empty result.

No slot props.

#default ​

Raw mode. Receives the flattened query state and its methods.

Rendered in both modes, so nested renderless children still mount.

Receives useQuery.Current<MaybeMasked<TData>> & Pick<Query, 'refetch' \| 'fetchMore' \| 'updateQuery' \| 'subscribeToMore' \| 'start' \| 'stop' \| 'restart'>.

Every field of useQuery.Current is present, so resultState narrows result here exactly as it does in script.

Exposed ​

A template ref receives the full useQuery.Result surface, with refs unwrapped.

vue
<template>
  <ApolloQuery ref="apollo" ... />
</template>

Released under the MIT License.