Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/src/common/query/lib/create-query-client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
serialize,
shouldDehydrateQuery,
shouldRedactErrors,
shouldRetryQuery,
} from "./utils";

export function createQueryClient({}: CreateQueryClientInput = {}): CreateQueryClientOutput {
Expand All @@ -26,6 +27,7 @@ export function createQueryClient({}: CreateQueryClientInput = {}): CreateQueryC
queries: {
queryKeyHashFn: hashKey,
refetchInterval: constants.times.refetch,
retry: shouldRetryQuery,
staleTime: constants.times.stale,
Comment thread
spietras marked this conversation as resolved.
},
},
Expand Down
11 changes: 11 additions & 0 deletions src/src/common/query/lib/create-query-client/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { Mutation, Query, QueryClient } from "@tanstack/react-query";

import { ORPCError } from "@orpc/contract";
import { defaultShouldDehydrateQuery, matchQuery } from "@tanstack/react-query";

import type { SerializedData } from "./types";

import { getExecutionContext } from "../../../generic/lib/get-execution-context";
import { serializer } from "./vars";

export function serialize(data: unknown) {
Expand Down Expand Up @@ -32,6 +34,15 @@ export function shouldRedactErrors() {
return false;
}

export function shouldRetryQuery(failureCount: number, error: unknown) {
if (getExecutionContext().context.runtime === "server") return false;

if (error instanceof ORPCError && error.status >= 400 && error.status < 500)
return false;

return failureCount < 3;
Comment thread
spietras marked this conversation as resolved.
}

export async function invalidateQueriesForMutation(
mutation: Mutation<unknown, unknown, unknown, unknown>,
client: QueryClient,
Expand Down
Loading