New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@urql/exchange-retry

Package Overview
Dependencies
Maintainers
25
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@urql/exchange-retry - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

7

CHANGELOG.md
# Changelog
## 1.2.0
### Minor Changes
- Reset `retryExchange`’s previous attempts and delay if an operation succeeds. This prevents the exchange from keeping its old retry count and delay if the operation delivered a result in the meantime. This is important for it to help recover from failing subscriptions
Submitted by [@kitten](https://github.com/kitten) (See [#3229](https://github.com/urql-graphql/urql/pull/3229))
## 1.1.1

@@ -4,0 +11,0 @@

45

dist/urql-exchange-retry.js

@@ -1,4 +0,3 @@

Object.defineProperty(exports, '__esModule', {
value: true
});
Object.defineProperty(exports, '__esModule', { value: true });
var wonka = require('wonka');

@@ -50,9 +49,9 @@ var core = require('@urql/core');

} = wonka.makeSubject();
var retryWithBackoff$ = wonka.mergeMap(op => {
var {
key,
context
} = op;
var retryCount = (context.retryCount || 0) + 1;
var delayAmount = context.retryDelay || MIN_DELAY;
var retryWithBackoff$ = wonka.mergeMap(operation => {
var retry = operation.context.retry || {
count: 0,
delay: null
};
var retryCount = ++retry.count;
var delayAmount = retry.delay || MIN_DELAY;
var backoffFactor = Math.random() + 1.5;

@@ -69,3 +68,3 @@ // if randomDelay is enabled and it won't exceed the max delay, apply a random

var teardown$ = wonka.filter(op => {
return (op.kind === 'query' || op.kind === 'teardown') && op.key === key;
return (op.kind === 'query' || op.kind === 'teardown') && op.key === operation.key;
})(operations$);

@@ -75,3 +74,3 @@ process.env.NODE_ENV !== 'production' ? dispatchDebug({

message: `The operation has failed and a retry has been triggered (${retryCount} / ${MAX_ATTEMPTS})`,
operation: op,
operation,
data: {

@@ -86,6 +85,5 @@ retryCount

// Stop retry if a teardown comes in
wonka.takeUntil(teardown$)(wonka.debounce(() => delayAmount)(wonka.fromValue(core.makeOperation(op.kind, op, {
...op.context,
retryDelay: delayAmount,
retryCount
wonka.takeUntil(teardown$)(wonka.debounce(() => delayAmount)(wonka.fromValue(core.makeOperation(operation.kind, operation, {
...operation.context,
retry
}))))

@@ -95,15 +93,21 @@ );

return wonka.filter(res => {
var retry = res.operation.context.retry;
// Only retry if the error passes the conditional retryIf function (if passed)
// or if the error contains a networkError
if (!res.error || (retryIf ? !retryIf(res.error, res.operation) : !retryWith && !res.error.networkError)) {
// Reset the delay state for a successful operation
if (retry) {
retry.count = 0;
retry.delay = null;
}
return true;
}
var maxNumberAttemptsExceeded = (res.operation.context.retryCount || 0) >= MAX_ATTEMPTS - 1;
var maxNumberAttemptsExceeded = (retry && retry.count || 0) >= MAX_ATTEMPTS - 1;
if (!maxNumberAttemptsExceeded) {
var operation = retryWith ? retryWith(res.error, res.operation) : res.operation;
if (!operation) return true;
var _operation = retryWith ? retryWith(res.error, res.operation) : res.operation;
if (!_operation) return true;
// Send failed responses to be retried by calling next on the retry$ subject
// Exclude operations that have been retried more than the specified max
nextRetryOperation(operation);
nextRetryOperation(_operation);
return false;

@@ -121,3 +125,4 @@ }

};
exports.retryExchange = retryExchange;
//# sourceMappingURL=urql-exchange-retry.js.map

@@ -1,2 +0,2 @@

Object.defineProperty(exports,"__esModule",{value:!0});var r=require("wonka"),e=require("@urql/core");exports.retryExchange=t=>{var{retryIf:o,retryWith:a}=t,n=t.initialDelayMs||1e3,u=t.maxDelayMs||15e3,i=t.maxNumberAttempts||2,y=null==t.randomDelay||!!t.randomDelay;return({forward:t})=>l=>{var{source:m,next:d}=r.makeSubject(),k=r.mergeMap((t=>{var{key:o,context:a}=t,i=(a.retryCount||0)+1,m=a.retryDelay||n,d=Math.random()+1.5;y&&m*d<u&&(m*=d);var k=r.filter((r=>("query"===r.kind||"teardown"===r.kind)&&r.key===o))(l);return r.takeUntil(k)(r.debounce((()=>m))(r.fromValue(e.makeOperation(t.kind,t,{...t.context,retryDelay:m,retryCount:i}))))}))(m);return r.filter((r=>{if(!r.error||!(o?o(r.error,r.operation):a||r.error.networkError))return!0;if(!((r.operation.context.retryCount||0)>=i-1)){var e=a?a(r.error,r.operation):r.operation;return!e||(d(e),!1)}return!0}))(t(r.merge([l,k])))}};
Object.defineProperty(exports,"__esModule",{value:!0});var r=require("wonka"),e=require("@urql/core");exports.retryExchange=t=>{var{retryIf:a,retryWith:n}=t,o=t.initialDelayMs||1e3,u=t.maxDelayMs||15e3,l=t.maxNumberAttempts||2,i=null==t.randomDelay||!!t.randomDelay;return({forward:t})=>y=>{var{source:d,next:c}=r.makeSubject(),m=r.mergeMap((t=>{var a=t.context.retry||{count:0,delay:null},n=(++a.count,a.delay||o),l=Math.random()+1.5;i&&n*l<u&&(n*=l);var d=r.filter((r=>("query"===r.kind||"teardown"===r.kind)&&r.key===t.key))(y);return r.takeUntil(d)(r.debounce((()=>n))(r.fromValue(e.makeOperation(t.kind,t,{...t.context,retry:a}))))}))(d);return r.filter((r=>{var e=r.operation.context.retry;if(!r.error||!(a?a(r.error,r.operation):n||r.error.networkError))return e&&(e.count=0,e.delay=null),!0;if(!((e&&e.count||0)>=l-1)){var t=n?n(r.error,r.operation):r.operation;return!t||(c(t),!1)}return!0}))(t(r.merge([y,m])))}};
//# sourceMappingURL=urql-exchange-retry.min.js.map
{
"name": "@urql/exchange-retry",
"version": "1.1.1",
"version": "1.2.0",
"description": "An exchange for operation retry support in urql",

@@ -27,5 +27,5 @@ "sideEffects": false,

".": {
"types": "./dist/urql-exchange-retry.d.ts",
"import": "./dist/urql-exchange-retry.mjs",
"require": "./dist/urql-exchange-retry.js",
"types": "./dist/urql-exchange-retry.d.ts",
"source": "./src/index.ts"

@@ -43,3 +43,3 @@ },

"graphql": "^16.0.0",
"@urql/core": "4.0.7"
"@urql/core": "4.0.8"
},

@@ -46,0 +46,0 @@ "dependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc