From 8aa8cb100c0e25cc3e48d8cbfc18a78b234a2096 Mon Sep 17 00:00:00 2001 From: Michael Bahr <1830132+bahrmichael@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:11:10 +0100 Subject: [PATCH 1/3] docs: add retry info for idempotency --- docs/advanced/retry-operations.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/advanced/retry-operations.md b/docs/advanced/retry-operations.md index d361eb1823..499478d626 100644 --- a/docs/advanced/retry-operations.md +++ b/docs/advanced/retry-operations.md @@ -113,3 +113,25 @@ const options = { }, }; ``` + +## Dealing with Idempotency + +The `operation` parameter may be used to determine if a request should be retried or not. This can be useful for requests that are not idempotent. For example if you only want to retry `query` operations, you can check [the `operation.kind` field](https://commerce.nearform.com/open-source/urql/docs/api/core/#operationtype). For more precise control, you can use the [other GraphQL request inputs](https://commerce.nearform.com/open-source/urql/docs/api/core/#graphqlrequest). + +```js +import { Client, cacheExchange, fetchExchange } from 'urql'; +import { retryExchange } from '@urql/exchange-retry'; + +const client = new Client({ + url: 'http://localhost:1234/graphql', + exchanges: [ + cacheExchange, + retryExchange({ + retryIf: (error, operation) => { + return !!(error && error.networkError) && operation.kind === 'query'; + }, + }), + fetchExchange, + ], +}); +``` From 8a1d015adb117378c8072491223c772fcb23dbc4 Mon Sep 17 00:00:00 2001 From: Michael Bahr <1830132+bahrmichael@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:13:28 +0100 Subject: [PATCH 2/3] rewording --- docs/advanced/retry-operations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced/retry-operations.md b/docs/advanced/retry-operations.md index 499478d626..a3c36dbd5d 100644 --- a/docs/advanced/retry-operations.md +++ b/docs/advanced/retry-operations.md @@ -116,7 +116,7 @@ const options = { ## Dealing with Idempotency -The `operation` parameter may be used to determine if a request should be retried or not. This can be useful for requests that are not idempotent. For example if you only want to retry `query` operations, you can check [the `operation.kind` field](https://commerce.nearform.com/open-source/urql/docs/api/core/#operationtype). For more precise control, you can use the [other GraphQL request inputs](https://commerce.nearform.com/open-source/urql/docs/api/core/#graphqlrequest). +To avoid retries in situations with non-idempotent requests, the `operation` parameter may also be useful to determine if a request should be retried or not. For example if you only want to retry `query` operations, you can check that [the `operation.kind` field](https://commerce.nearform.com/open-source/urql/docs/api/core/#operationtype) has the value `query`. For more precise control, you can use the [other GraphQL request inputs](https://commerce.nearform.com/open-source/urql/docs/api/core/#graphqlrequest). ```js import { Client, cacheExchange, fetchExchange } from 'urql'; From cf26ad3c65c5c57576e5ae43e82ce4b50132de19 Mon Sep 17 00:00:00 2001 From: Michael Bahr <1830132+bahrmichael@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:13:53 +0100 Subject: [PATCH 3/3] Update retry-operations.md --- docs/advanced/retry-operations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced/retry-operations.md b/docs/advanced/retry-operations.md index a3c36dbd5d..ea9735f5c7 100644 --- a/docs/advanced/retry-operations.md +++ b/docs/advanced/retry-operations.md @@ -116,7 +116,7 @@ const options = { ## Dealing with Idempotency -To avoid retries in situations with non-idempotent requests, the `operation` parameter may also be useful to determine if a request should be retried or not. For example if you only want to retry `query` operations, you can check that [the `operation.kind` field](https://commerce.nearform.com/open-source/urql/docs/api/core/#operationtype) has the value `query`. For more precise control, you can use the [other GraphQL request inputs](https://commerce.nearform.com/open-source/urql/docs/api/core/#graphqlrequest). +To avoid retries for non-idempotent requests, the `operation` parameter may also be useful to determine if a request should be retried or not. For example if you only want to retry `query` operations, you can check that [the `operation.kind` field](https://commerce.nearform.com/open-source/urql/docs/api/core/#operationtype) has the value `query`. For more precise control, you can use the [other GraphQL request inputs](https://commerce.nearform.com/open-source/urql/docs/api/core/#graphqlrequest). ```js import { Client, cacheExchange, fetchExchange } from 'urql';