Skip to main content

Query API

After configuring the builder, you can use it inside your React components with the hooks exposed in this page.

The query builder provides a set of hooks similar to Tanstack Query itself. Each hook can be passed the variables for that builder, as well as the options object that is passed to the underlying Tanstack Query hook.

Tanstack Query normally provides a set of hooks for various use cases. These are useQuery, useInfiniteQuery, useMutation, and useQueries. There are also some variants like useSuspenseQuery and usePrefetchQuery.

Query hooks

useQuery

useQuery(vars, queryOptions): QueryResult;

There are also usePrefetchQuery and useSuspenseQuery variants.

useQueries

useQueries(queries: Array<{ vars, options, mapKey }>, sharedVars, sharedOptions): QueriesResult;

There is also useSuspenseQueries variant.

useInfiniteQuery

useInfiniteQuery(vars, queryOptions): InfiniteQueryResult;

Infinite query methods are only available if you have configured the builder with withPagination.

There are also usePrefetchInfiniteQuery and useSuspenseInfiniteQuery variants.

useIsFetching

useIsFetching(vars, queryFilters): number;

Mutation hooks

Each builder can be used for query or mutation. It's up to the developer to decide how to use it. The underlying query/mutation functions are the same. Only the underlying Tanstack Query hooks, and options passed to them are different.

useMutation

useMutation(mutationOptions): UseMutationResult;

useMutationState

useMutationState(vars, mutationFilters, select): Mutation | SelectedState;

useIsMutating

useIsMutating(vars, mutationFilters): number;

Utilities

There are some utility functions that are not hooks, but can be used for more advanced use cases, such as calling underlying Tanstack Query hooks directly.

getQueryFn(operationType: 'query' | 'queries' | 'infiniteQuery'): QueryFn;
getQueryKeyHashFn(): QueryKeyHashFn;
getQueryKey(vars): QueryKey;
getQueryOptions(vars, queryOptions, operationType): QueryOptions;
getInfiniteQueryOptions(vars, paginataionOptions): InfiniteQueryOptions;
getMutationFn(queryClient, meta): MutationFn;
getMutationKey(): MutationKey;
getMutationOptions(queryClient, mutationOptions): MutationOptions;
getMutationFilters(vars, mutationFilters): MutationFilters;