Skip to content

Query Package Overview

@graphql-suite/query provides React hooks that connect @graphql-suite/client to TanStack Query. You get automatic caching, background refetching, and cache invalidation on mutations without writing any of the plumbing yourself.

  • GraphQLProvider — React context provider that makes the GraphQL client available to all hooks
  • useGraphQLClient() — returns the client from context for raw client.execute() calls
HookPurpose
useEntityQueryFetch a single entity by filter
useEntityListFetch a list with filtering, ordering, and pagination
useEntityInfiniteQueryInfinite-scroll pagination with automatic page tracking

All query hooks return the standard TanStack Query result object (data, isPending, error, refetch, etc.).

HookPurpose
useEntityInsertInsert one or more rows
useEntityUpdateUpdate rows matching a filter
useEntityDeleteDelete rows matching a filter

Mutation hooks automatically invalidate cached queries after a successful mutation by default. You can control this with the invalidate and invalidateKey options.

HookPurpose
useEntityObtain an entity client from the provider context by name
useGraphQLClientAccess the underlying GraphQLClient for raw queries
@graphql-suite/client
@tanstack/react-query >= 5
react >= 18
import { useEntityList } from '@graphql-suite/query'
function ArticleList() {
const { data, isPending } = useEntityList(articleEntity, {
select: { id: true, title: true, author: { name: true } },
orderBy: { createdAt: { direction: 'desc', priority: 1 } },
limit: 10,
})
if (isPending) return <p>Loading...</p>
return (
<ul>
{data?.map((article) => (
<li key={article.id}>{article.title}{article.author?.name}</li>
))}
</ul>
)
}