# ApolloQuery component
Example:
<ApolloQuery
:query="gql => gql`
query MyHelloQuery ($name: String!) {
hello (name: $name)
}
`"
:variables="{ name }"
>
<template v-slot="{ result: { error, data }, isLoading }">
<!-- Loading -->
<div v-if="isLoading" class="loading apollo">Loading...</div>
<!-- Error -->
<div v-else-if="error" class="error apollo">An error occurred</div>
<!-- Result -->
<div v-else-if="data" class="result apollo">{{ data.hello }}</div>
<!-- No result -->
<div v-else class="no-result apollo">No result :(</div>
</template>
</ApolloQuery>
WARNING
To enable support of gql
string tag in Vue templates, see the necessary setup in the guide.
# Props
query
: GraphQL query (transformed bygraphql-tag
) or a function that receives thegql
tag as argument and should return the transformed queryvariables
: Object of GraphQL variablesfetchPolicy
: See apollo fetchPolicy (opens new window)pollInterval
: Number of milliseconds. Polling provides near-real-time synchronization with your server by causing a query to execute periodically at a specified interval.notifyOnNetworkStatusChange
: See Inspecting loading states (opens new window)context
: See apollo context (opens new window)update
: Function to transform the resultdata
, useful for picking a specific part of the response. Example::update="data => data.user.messages"
skip
: Boolean disabling query fetchingclientId
: id of the Apollo Client used by the query (defined in ApolloProviderclients
option)deep
: Boolean to use deep Vue watcherstag
: String HTML tag name (default:div
); if falsy (for examplenull
orundefined
), the component will be renderless (the content won't be wrapped in a tag), in this case, only the first child will be rendereddebounce
: Number of milliseconds for debouncing refetches (for example when the variables are changed)throttle
: Number of milliseconds for throttling refetches (for example when the variables are changed)prefetch
: Iffalse
, will skip prefetching during SSRoptions
: Other Apollo Watch Query options
# Scoped slot
result
: Apollo Query resultresult.data
: Data returned by the query (can be transformed by theupdate
prop)result.fullData
: Raw data returned by the query (not transformed by theupdate
prop)result.loading
: Boolean indicating that a request is in flight (you may need to setnotifyOnNetworkStatusChange
prop for it to change)result.error
: Eventual error for the current resultresult.networkStatus
: See apollo networkStatus (opens new window)
query
: Smart Query associated with the component. It's useful to do some operations likequery.refetch()
orquery.fetchMore()
.isLoading
: Smart Query loading stategqlError
: first GraphQL error if anytimes
: number of times the result was updated
# Events
result(resultObject)
error(errorObject)
loading(boolean)