Skip to content

Commit

Permalink
support invalidate all queries (#3899)
Browse files Browse the repository at this point in the history
* support invalidate all queries

* Add changeset

* Update .changeset/stupid-rabbits-jump.md

Co-authored-by: Dillon Raphael <[email protected]>

Co-authored-by: Aleksandra <[email protected]>
Co-authored-by: Dillon Raphael <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2022
1 parent 77b7da0 commit 0025856
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-rabbits-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blitzjs/rpc": patch
---

Support full api of tanstack invalidateQueries
29 changes: 13 additions & 16 deletions packages/blitz-rpc/src/data-client/react-query-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,20 @@ export function getInfiniteQueryKey<TInput, TResult, T extends AsyncFunc>(
return [...queryKey, "infinite"]
}

type InvalidateQueryTypeWithParams = <TInput, TResult, T extends AsyncFunc>(
resolver: T | Resolver<TInput, TResult> | RpcClient<TInput, TResult>,
...params: [TInput]
) => Promise<void>
type InvalidateQueryTypeAllQueries = <TInput, TResult, T extends AsyncFunc>(
resolver: T | Resolver<TInput, TResult> | RpcClient<TInput, TResult>,
) => Promise<void>
type InvalidateQueryType = InvalidateQueryTypeWithParams & InvalidateQueryTypeAllQueries

export const invalidateQuery: InvalidateQueryType = (resolver, ...params: []) => {
if (typeof resolver === "undefined") {
throw new Error(
"invalidateQuery is missing the first argument - it must be a resolver function",
)
}
interface InvalidateQuery {
<TInput, TResult, T extends AsyncFunc>(
resolver: T | Resolver<TInput, TResult> | RpcClient<TInput, TResult>,
...params: [TInput]
): Promise<void>
<TInput, TResult, T extends AsyncFunc>(
resolver: T | Resolver<TInput, TResult> | RpcClient<TInput, TResult>,
): Promise<void>
(): Promise<void>
}

const fullQueryKey = getQueryKey(resolver, ...params)
export const invalidateQuery: InvalidateQuery = (resolver = undefined, ...params: []) => {
const fullQueryKey =
typeof resolver === "undefined" ? undefined : getQueryKey(resolver, ...params)
return getQueryClient().invalidateQueries(fullQueryKey)
}

Expand Down

0 comments on commit 0025856

Please sign in to comment.