Apollo Elements Guides API Blog

Haunted: useQuery

Apollo useQuery hook for web components. Elements that call useQuery inherit the ApolloQueryInterface.

Read the query component guides for examples and tips.

Exports

import { useQuery } from '@apollo-elements/haunted/useQuery';

useQuery

Parameters

query

TypedDocumentNode|DocumentNode

options

QueryHookOptions<D, V>
Option Type Description
client
ApolloClient
ApolloClient instance use to make the call.
context
Record<string, unknown>
Context object passed through the link execution chain.
errorPolicy
ErrorPolicy
Error policy to use for the mutation. See errorPolicy
fetchPolicy
FetchPolicy
See fetchPolicy
nextFetchPolicy
FetchPolicy
See nextFetchPolicy
noAutoSubscribe
boolean
See noAutoSubscribe
notifyOnNetworkStatusChange See notifyOnNetworkStatusChange
onCompleted
(data: D) => void
Callback for when the query resolves.
onError See onError Callback for when an error occurs.
partialRefetch
boolean
See partialRefetch
pollInterval
number
See pollInterval
query
DocumentNode | TypedDocumentNode
A GraphQL document that consists of a single query to be sent down to the server.
returnPartialData
boolean
See returnPartialData
shouldSubscribe See shouldSubscribe Predicate which determines whether or not to automatically subscribe
variables
Variables<D, V> 
A map going from variable name to variable value, where the variables are used within the GraphQL query.

Returns

QueryResult<D, V>
Property Type Description
data
Data<D>
Latest query data.
error
ApolloError
See error
loading
boolean
Whether the request is in-flight.
refetch See refetch
client
ApolloClient
ApolloClient instance use to make the call.
called
boolean
Relevant to subscriptions only.
fetchMore See fetchMore
networkStatus
NetworkStatus
See networkStatus
variables
boolean
Query variables used in the call.
startPolling
(ms: number) => void
Call to start polling the query.
stopPolling
() => void 
Call to stop polling the query.
subscribeToMore See subscribeToMore