建议: 在调用 `createClient` 时,在文档中明确指出只能有一个 `retryExchange`。
作者: rfrankspk创建于 2023年7月31日更新于 2023年8月1日
标签documentation 📖
/**
- This exchange is used to retry a GraphQL request if it fails due to a canceled context error.
- @param opts the options for the retry exchange
- @returns An exchange that will retry a GraphQL request if it fails due to a canceled context error */ export const canceledContextErrorRetryExchange = ({ initialDelayMs = 1000, maxDelayMs = 15000, randomDelay = true, maxNumberAttempts = 2, }): Exchange => { return retryExchange({ initialDelayMs, maxDelayMs, randomDelay, maxNumberAttempts, retryIf: (err: any) => err && err.message?.includes("context canceled"), }); };
/**
- This exchange is used to retry a GraphQL request if it fails due to a GraphQL API error.
- @param opts the options for the retry exchange
- @returns An exchange that will retry a GraphQL request if it fails due to a GraphQL API error */ export const graphQLErrorRetryExchange = ({ initialDelayMs = 1000, maxDelayMs = 15000, randomDelay = true, maxNumberAttempts = 2, }): Exchange => { return retryExchange({ initialDelayMs, maxDelayMs, randomDelay, maxNumberAttempts, retryIf: (err: any) => err && err.graphQLErrors?.length > 0, }); };
/**
- This exchange is used to retry a GraphQL request if it fails due to a network error.
- @param opts the options for the retry exchange
- @returns An exchange that will retry a GraphQL request if it fails due to a network error */ export const networkErrorRetryExchange = ({ initialDelayMs = 1000, maxDelayMs = 15000, randomDelay = true, maxNumberAttempts = 2, }): Exchange => { return retryExchange({ initialDelayMs, maxDelayMs, randomDelay, maxNumberAttempts, retryIf: (err: any) => err && err.networkError, }); };
export const generateGraphQLClient = ( configs: DataProviderConfig[], environment?: string, appId?: string, onError?: (error: CombinedError, operation: Operation) => void ): Client => { const defaultConfig = configs[0]; const { url: defaultUrl } = defaultConfig;
return createClient({ url: defaultUrl || "http://localhost:4002/graphql", fetch: async (input, init) => { const controller = new AbortController();
// timeout long running requests after 30 seconds
…
内容来源: urql-graphql/urql