Skip to content

useQueryHandle

Like useQuery, but returns a full DocumentHandle with methods for refetching and pagination.

import { graphql, useQueryHandle } from '$houdini'
export function ShowList() {
const { data, loadNext, loadNextPending, pageInfo, fetch } = useQueryHandle(
graphql(`
query AllShows {
shows @paginate(limit: 10) {
id
title
}
}
`)
)
return (
<>
{data.shows.map((show) => <div key={show.id}>{show.title}</div>)}
{pageInfo?.hasNextPage && (
<button onClick={() => loadNext(10)} disabled={loadNextPending}>
Load more
</button>
)}
<button onClick={() => fetch()}>Refresh</button>
</>
)
}

Signature

function useQueryHandle(document, variables?, config?): DocumentHandle

UseQueryConfig

OptionTypeDescription
policyCachePolicyOverride the cache policy for this query
metadataApp.MetadataPassed through to client plugins
fetchKeyanyChange this value to force a refetch

DocumentHandle

FieldTypeDescription
dataquery dataThe current result
fetchingbooleanTrue while a network request is in flight
errorsGraphQLError[] | nullAny errors from the last response
partialbooleanTrue if the result was served partially from cache
variablesobjectThe variables used for the current result
fetchfunctionTrigger a refetch, optionally with new variables
loadNextfunctionLoad the next page (cursor or offset pagination)
loadNextPendingbooleanTrue while loadNext is in flight
loadPreviousfunctionLoad the previous page (cursor pagination only)
loadPreviousPendingbooleanTrue while loadPrevious is in flight
pageInfoPageInfoCursor pagination metadata

Pagination fields are only present when the query uses @paginate.