-
Notifications
You must be signed in to change notification settings - Fork 389
[GraphQL-Client][Feature]Add the retries feature to the client #1017
Conversation
await sleep(resetTime); | ||
return httpFetch(params, nextCount, maxTries); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This error only occurs when the request was abandoned (eg. no network).
If the server has responded, the client will return the last server response (as per the previous block).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it @melissaluu! We were only discussing this yesterday.
LGTM - will defer to @paulomarg for the ✅
|
||
return response; | ||
} catch (error) { | ||
if (nextCount <= maxTries) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forget where we landed on logging - would it be worth letting them know when a retry occurs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't implemented logging yet - that's my next task 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're a wizard. :TIL: x 100
60caf87
to
171cb94
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all LGTM!
packages/graphql-client/README.md
Outdated
| headers? | `{[key: string]: string}` | Additional and/or replacement headers to be used in the request | | ||
| retries? | `number` | Alternative number of retries for the request. Retries only occur for requests that were abandoned or if the server responds with a `Too Many Request (429)` or `Service Unavailable (503)` response. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to do this for any 5XX
error? I guess we don't want to end up flooding the server with retries if there's an actual outage going on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah - the last thing we want to do is to flood the server when there's an actual outage - let's stick with only retrying for 503s
for now (since this is a status code that does support retries - it's 1 of 3 status' that can return a retry-after
header) and then we can see if devs gives other feedback and we can reevaluate.
@paulomarg - do you think we should make an upper limit on how many retries a dev can set? The last thing we want is for someone to set a ridiculous # for retries 🤔 😨 I'm thinking 5 or 10? thoughts? |
Definitely a good call. I would even be a little stricter, I wouldn't go past 5 - this is meant to be a way to recover for certain niche cases like an idempotent job or some such, not a way to brute force requests until they work. |
@paulomarg - if we're good with being stricter, I'd go for max |
a1e52ef
to
efc66ea
Compare
WHY are these changes introduced?
We are adding the
retries
feature to thegraphql-client
to enable auto retrying of failed HTTP requests in both thefetch
andrequest
function. The HTTP request retries only occurs in the following conditions:429 - Too Many Request
503 - Service Unavailable
A
1s
delay is used between each network retries.Client users are able to set the number of retries in 2 ways:
retries
config field during client initialization - this value will be applied to all HTTP requests by the clientretries
value in theRequestOptions
config per requestBy default, the client's
retries
value is set to0
if none was passed in the initialization configuration.WHAT is this pull request doing?
This PR adds the
retries
settings and functionalities to thegraphql-client
.Type of change
Checklist
yarn changeset
to create a draft changelog entry (do NOT update theCHANGELOG.md
file manually)