1 | import type { BaseQueryApi, BaseQueryArg, BaseQueryEnhancer, BaseQueryExtraOptions, BaseQueryFn } from './baseQueryTypes';
|
2 | import type { FetchBaseQueryError } from './fetchBaseQuery';
|
3 | declare type RetryConditionFunction = (error: FetchBaseQueryError, args: BaseQueryArg<BaseQueryFn>, extraArgs: {
|
4 | attempt: number;
|
5 | baseQueryApi: BaseQueryApi;
|
6 | extraOptions: BaseQueryExtraOptions<BaseQueryFn> & RetryOptions;
|
7 | }) => boolean;
|
8 | export declare type RetryOptions = {
|
9 | /**
|
10 | * Function used to determine delay between retries
|
11 | */
|
12 | backoff?: (attempt: number, maxRetries: number) => Promise<void>;
|
13 | } & ({
|
14 | /**
|
15 | * How many times the query will be retried (default: 5)
|
16 | */
|
17 | maxRetries?: number;
|
18 | retryCondition?: undefined;
|
19 | } | {
|
20 | /**
|
21 | * Callback to determine if a retry should be attempted.
|
22 | * Return `true` for another retry and `false` to quit trying prematurely.
|
23 | */
|
24 | retryCondition?: RetryConditionFunction;
|
25 | maxRetries?: undefined;
|
26 | });
|
27 | declare function fail(e: any): never;
|
28 | /**
|
29 | * A utility that can wrap `baseQuery` in the API definition to provide retries with a basic exponential backoff.
|
30 | *
|
31 | * @example
|
32 | *
|
33 | * ```ts
|
34 | * // codeblock-meta title="Retry every request 5 times by default"
|
35 | * import { createApi, fetchBaseQuery, retry } from '@reduxjs/toolkit/query/react'
|
36 | * interface Post {
|
37 | * id: number
|
38 | * name: string
|
39 | * }
|
40 | * type PostsResponse = Post[]
|
41 | *
|
42 | * // maxRetries: 5 is the default, and can be omitted. Shown for documentation purposes.
|
43 | * const staggeredBaseQuery = retry(fetchBaseQuery({ baseUrl: '/' }), { maxRetries: 5 });
|
44 | * export const api = createApi({
|
45 | * baseQuery: staggeredBaseQuery,
|
46 | * endpoints: (build) => ({
|
47 | * getPosts: build.query<PostsResponse, void>({
|
48 | * query: () => ({ url: 'posts' }),
|
49 | * }),
|
50 | * getPost: build.query<PostsResponse, string>({
|
51 | * query: (id) => ({ url: `post/${id}` }),
|
52 | * extraOptions: { maxRetries: 8 }, // You can override the retry behavior on each endpoint
|
53 | * }),
|
54 | * }),
|
55 | * });
|
56 | *
|
57 | * export const { useGetPostsQuery, useGetPostQuery } = api;
|
58 | * ```
|
59 | */
|
60 | export declare const retry: BaseQueryEnhancer<unknown, RetryOptions, void | RetryOptions> & {
|
61 | fail: typeof fail;
|
62 | };
|
63 | export {};
|