import { TRPCClient, TRPCClientError, TRPCRequestOptions } from "@trpc/client"; import type { AnyRouter, inferHandlerInput, inferProcedureInput, inferProcedureOutput, } from "@trpc/server"; import { createContext } from "solid-js"; import { CancelOptions, FetchInfiniteQueryOptions, FetchQueryOptions, InfiniteData, InvalidateOptions, InvalidateQueryFilters, QueryClient, RefetchOptions, RefetchQueryFilters, SetDataOptions, } from "@tanstack/solid-query"; import { Updater } from "@tanstack/solid-query"; interface TRPCFetchQueryOptions extends FetchQueryOptions, TRPCRequestOptions {} interface TRPCFetchInfiniteQueryOptions extends FetchInfiniteQueryOptions, TRPCRequestOptions {} export interface TRPCContextState { queryClient: QueryClient; client: TRPCClient; /** * @link https://react-query.tanstack.com/guides/prefetching */ fetchQuery< TPath extends keyof TRouter["_def"]["queries"] & string, TProcedure extends TRouter["_def"]["queries"][TPath], TOutput extends inferProcedureOutput, TInput extends inferProcedureInput >( pathAndInput: [path: TPath, ...args: inferHandlerInput], opts?: TRPCFetchQueryOptions, TOutput> ): Promise; /** * @link https://react-query.tanstack.com/guides/prefetching */ fetchInfiniteQuery< TPath extends keyof TRouter["_def"]["queries"] & string, TProcedure extends TRouter["_def"]["queries"][TPath], TOutput extends inferProcedureOutput, TInput extends inferProcedureInput >( pathAndInput: [path: TPath, ...args: inferHandlerInput], opts?: TRPCFetchInfiniteQueryOptions< TInput, TRPCClientError, TOutput > ): Promise>; /** * @link https://react-query.tanstack.com/guides/prefetching */ prefetchQuery< TPath extends keyof TRouter["_def"]["queries"] & string, TProcedure extends TRouter["_def"]["queries"][TPath], TOutput extends inferProcedureOutput, TInput extends inferProcedureInput >( pathAndInput: [path: TPath, ...args: inferHandlerInput], opts?: TRPCFetchQueryOptions, TOutput> ): Promise; /** * @link https://react-query.tanstack.com/guides/prefetching */ prefetchInfiniteQuery< TPath extends keyof TRouter["_def"]["queries"] & string, TProcedure extends TRouter["_def"]["queries"][TPath], TOutput extends inferProcedureOutput, TInput extends inferProcedureInput >( pathAndInput: [path: TPath, ...args: inferHandlerInput], opts?: TRPCFetchInfiniteQueryOptions< TInput, TRPCClientError, TOutput > ): Promise; /** * @deprecated use `invalidateQueries` */ invalidateQuery< TPath extends keyof TRouter["_def"]["queries"] & string, TInput extends inferProcedureInput >( pathAndInput: [TPath, TInput?], options?: InvalidateOptions ): Promise; /** * @link https://react-query.tanstack.com/guides/query-invalidation */ invalidateQueries< TPath extends keyof TRouter["_def"]["queries"] & string, TInput extends inferProcedureInput >( pathAndInput?: [TPath, TInput?] | TPath, filters?: InvalidateQueryFilters, options?: InvalidateOptions ): Promise; /** * @link https://react-query.tanstack.com/guides/query-invalidation */ invalidateQueries( filters?: InvalidateQueryFilters, options?: InvalidateOptions ): Promise; /** * @link https://react-query.tanstack.com/reference/QueryClient#queryclientrefetchqueries */ refetchQueries< TPath extends keyof TRouter["_def"]["queries"] & string, TInput extends inferProcedureInput >( pathAndInput: [TPath, TInput?], filters?: RefetchQueryFilters, options?: RefetchOptions ): Promise; /** * @link https://react-query.tanstack.com/reference/QueryClient#queryclientrefetchqueries */ refetchQueries( filters?: RefetchQueryFilters, options?: RefetchOptions ): Promise; /** * @link https://react-query.tanstack.com/guides/query-cancellation */ cancelQuery< TPath extends keyof TRouter["_def"]["queries"] & string, TInput extends inferProcedureInput >( pathAndInput: [TPath, TInput?], options?: CancelOptions ): Promise; /** * @link https://react-query.tanstack.com/reference/QueryClient#queryclientsetquerydata */ setQueryData< TPath extends keyof TRouter["_def"]["queries"] & string, TInput extends inferProcedureInput, TOutput extends inferProcedureOutput >( pathAndInput: [TPath, TInput?], updater: Updater, options?: SetDataOptions ): void; /** * @link https://react-query.tanstack.com/reference/QueryClient#queryclientgetquerydata */ getQueryData< TPath extends keyof TRouter["_def"]["queries"] & string, TInput extends inferProcedureInput, TOutput extends inferProcedureOutput >( pathAndInput: [TPath, TInput?] ): TOutput | undefined; /** * @link https://react-query.tanstack.com/reference/QueryClient#queryclientgetquerydata */ setInfiniteQueryData< TPath extends keyof TRouter["_def"]["queries"] & string, TInput extends inferProcedureInput, TOutput extends inferProcedureOutput >( pathAndInput: [TPath, TInput?], updater: Updater | undefined, InfiniteData>, options?: SetDataOptions ): void; /** * @link https://react-query.tanstack.com/reference/QueryClient#queryclientgetquerydata */ getInfiniteQueryData< TPath extends keyof TRouter["_def"]["queries"] & string, TInput extends inferProcedureInput, TOutput extends inferProcedureOutput >( pathAndInput: [TPath, TInput?] ): InfiniteData | undefined; } export const TRPCContext = createContext(null as any);