Skip to content

Commit 226f24e

Browse files
AnthonyMDevgh-action-runner
authored andcommitted
Add Docs comment for retrying from HTTPInterceptor (#845)
1 parent eb25b18 commit 226f24e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

docs/source/advanced/request-chain.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ struct AuthHeaderInterceptor: GraphQLInterceptor {
175175

176176
[`HTTPInterceptor`](https://www.apollographql.com/docs/ios/docc/documentation/apollo/httpinterceptor) requires you to implement the `intercept(request: next:)` function to perform pre-flight work on the `URLRequest` and post-flight work on the `HTTPResponse`, including the raw response `Data` stream.
177177

178-
After the `RequestChain` proceeds through the `GraphQLInterceptor`s provided by it's `InterceptorProvider`, it will call `GraphQLRequest/toURLRequest()` on the final `GraphQLRequest`. Each `HTTPInterceptor` provided by the `InterceptorProvider` will then have it's `intercept(request:next:)` function called in sequential order prior to fetching the request.
178+
After the `RequestChain` proceeds through each `GraphQLInterceptor` provided by it's `InterceptorProvider`, it will call `GraphQLRequest/toURLRequest()` on the final `GraphQLRequest`. Each `HTTPInterceptor` provided by the `InterceptorProvider` will then have it's `intercept(request:next:)` function called in sequential order prior to fetching the request.
179179

180180
The `intercept` function works as follows:
181181

@@ -193,6 +193,12 @@ The `intercept` function works as follows:
193193
- Return the `HTTPResponse`
194194
- When finished, your interceptor must return the `HTTPResponse`, which will be passed back up the chain to the previous `HTTPInterceptor`.
195195

196+
<Note>
197+
198+
Because an `HTTPInterceptor` does not have access to the `GraphQLRequest`, it cannot trigger a `RequestChain.Retry`. We recommend throwing a custom error from a failing `HTTPInterceptor` and implementing a `GraphQLInterceptor` responsible for error handling to catch the error and trigger a retry with the appropriate `GraphQLRequest`.
199+
200+
</Note>
201+
196202
### CacheInterceptor
197203

198204
[`CacheInterceptor`](https://www.apollographql.com/docs/ios/docc/documentation/apollo/cacheinterceptor) implementations handle cache read and write operations with custom logic beyond what's available through [type/field policies](./../caching/cache-key-resolution). A `CacheInterceptor` must provide two functions, `readCacheData(from store: request:)` and `writeCacheData(to store: request: response)`.
@@ -258,7 +264,7 @@ If you are using a response format other than JSON or that differs from the Grap
258264

259265
## Request retries
260266

261-
Any interceptor can trigger a request retry by throwing a `RequestChain.Retry` error. When a `RequestChain` receives a thrown `Retry` error, it will restart from the beginning of the [request chain flow](#request-chain-flow) using the `request` provided by the error. This allows the request to be modified to correct errors that may be causing the failure prior to beginning again.
267+
Any `GraphQLInterceptor` can trigger a request retry by throwing a `RequestChain.Retry` error. When a `RequestChain` receives a thrown `Retry` error, it will restart from the beginning of the [request chain flow](#request-chain-flow) using the `request` provided by the error. This allows the request to be modified to correct errors that may be causing the failure prior to beginning again.
262268

263269
### Preventing infinite retry loops
264270

0 commit comments

Comments
 (0)