apollo-link-timeout 5.0.2 → 5.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/timeoutLink.js
CHANGED
|
@@ -54,6 +54,10 @@ var TimeoutLink = /** @class */ (function (_super) {
|
|
|
54
54
|
var ourController;
|
|
55
55
|
// override timeout from query context
|
|
56
56
|
var requestTimeout = operation.getContext().timeout || this.timeout;
|
|
57
|
+
var operationType = operation.query.definitions.find(function (def) { return def.kind === 'OperationDefinition'; }).operation;
|
|
58
|
+
if (requestTimeout <= 0 || operationType === 'subscription') {
|
|
59
|
+
return forward(operation); // skip this link if timeout is zero or it's a subscription request
|
|
60
|
+
}
|
|
57
61
|
// add abort controller and signal object to fetchOptions if they don't already exist
|
|
58
62
|
if (typeof AbortController !== 'undefined') {
|
|
59
63
|
var context = operation.getContext();
|
|
@@ -64,10 +68,6 @@ var TimeoutLink = /** @class */ (function (_super) {
|
|
|
64
68
|
operation.setContext({ fetchOptions: fetchOptions });
|
|
65
69
|
}
|
|
66
70
|
var chainObservable = forward(operation); // observable for remaining link chain
|
|
67
|
-
var operationType = operation.query.definitions.find(function (def) { return def.kind === 'OperationDefinition'; }).operation;
|
|
68
|
-
if (requestTimeout <= 0 || operationType === 'subscription') {
|
|
69
|
-
return chainObservable; // skip this link if timeout is zero or it's a subscription request
|
|
70
|
-
}
|
|
71
71
|
// create local observable with timeout functionality (unsubscibe from chain observable and
|
|
72
72
|
// return an error if the timeout expires before chain observable resolves)
|
|
73
73
|
var localObservable = new core_1.Observable(function (observer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeoutLink.js","sourceRoot":"","sources":["../../src/timeoutLink.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yFAAyF;AACzF,
|
|
1
|
+
{"version":3,"file":"timeoutLink.js","sourceRoot":"","sources":["../../src/timeoutLink.ts"],"names":[],"mappings":";;;;;;;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,yBAAY,CAAC,kBAAkB,EAAE,cAAc,EAAE,KAAI,CAAC,UAAU,CAAC,CAAC,CAAC;gBACtF,YAAY,CAAC,WAAW,EAAE,CAAC;YAC7B,CAAC,EAAE,cAAc,CAAC,CAAC;YAEnB,IAAM,aAAa,GAAG;gBACpB,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,YAAY,CAAC,WAAW,EAAE,CAAC;YAC7B,CAAC,CAAC;YAEF,IAAM,MAAM,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC;YACjD,IAAI,MAAM,EAAE;gBACV,MAAM,CAAC,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC,CAAC;aACxC;YAED,gDAAgD;YAChD,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE;gBAC1C,aAAa,EAAE,CAAC;YAClB,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAEnB,0EAA0E;YAC1E,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC,CAAC;QAEH,OAAO,eAAe,CAAC;IACzB,CAAC;IACH,kBAAC;AAAD,CAAC,AA9GD,CAAyC,iBAAU,GA8GlD"}
|
package/lib/esm/timeoutLink.js
CHANGED
|
@@ -52,6 +52,10 @@ var TimeoutLink = /** @class */ (function (_super) {
|
|
|
52
52
|
var ourController;
|
|
53
53
|
// override timeout from query context
|
|
54
54
|
var requestTimeout = operation.getContext().timeout || this.timeout;
|
|
55
|
+
var operationType = operation.query.definitions.find(function (def) { return def.kind === 'OperationDefinition'; }).operation;
|
|
56
|
+
if (requestTimeout <= 0 || operationType === 'subscription') {
|
|
57
|
+
return forward(operation); // skip this link if timeout is zero or it's a subscription request
|
|
58
|
+
}
|
|
55
59
|
// add abort controller and signal object to fetchOptions if they don't already exist
|
|
56
60
|
if (typeof AbortController !== 'undefined') {
|
|
57
61
|
var context = operation.getContext();
|
|
@@ -62,10 +66,6 @@ var TimeoutLink = /** @class */ (function (_super) {
|
|
|
62
66
|
operation.setContext({ fetchOptions: fetchOptions });
|
|
63
67
|
}
|
|
64
68
|
var chainObservable = forward(operation); // observable for remaining link chain
|
|
65
|
-
var operationType = operation.query.definitions.find(function (def) { return def.kind === 'OperationDefinition'; }).operation;
|
|
66
|
-
if (requestTimeout <= 0 || operationType === 'subscription') {
|
|
67
|
-
return chainObservable; // skip this link if timeout is zero or it's a subscription request
|
|
68
|
-
}
|
|
69
69
|
// create local observable with timeout functionality (unsubscibe from chain observable and
|
|
70
70
|
// return an error if the timeout expires before chain observable resolves)
|
|
71
71
|
var localObservable = new Observable(function (observer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeoutLink.js","sourceRoot":"","sources":["../../src/timeoutLink.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yFAAyF;AACzF,OAAO,EAAE,UAAU,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"timeoutLink.js","sourceRoot":"","sources":["../../src/timeoutLink.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yFAAyF;AACzF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAmD,MAAM,qBAAqB,CAAC;AAE9G,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAE7C,IAAM,eAAe,GAAW,KAAK,CAAC;AAEtC;;GAEG;AACH;IAAyC,+BAAU;IAIjD;;;;;;OAMG;IACH,qBAAY,OAAgB,EAAE,UAAmB;QAAjD,YACE,iBAAO,SAGR;QAFC,KAAI,CAAC,OAAO,GAAG,OAAO,IAAI,eAAe,CAAC;QAC1C,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;;IAC/B,CAAC;IAEM,6BAAO,GAAd,UAAe,SAAoB,EAAE,OAAiB;QAAtD,iBA4FC;QA3FC,IAAI,UAA2B,CAAC;QAChC,IAAI,aAA8B,CAAC;QAEnC,sCAAsC;QACtC,IAAM,cAAc,GAAG,SAAS,CAAC,UAAU,EAAE,C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,EAAE,CAAC;YAClB,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAEnB,0EAA0E;YAC1E,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC,CAAC;QAEH,OAAO,eAAe,CAAC;IACzB,CAAC;IACH,kBAAC;AAAD,CAAC,AA9GD,CAAyC,UAAU,GA8GlD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="zen-observable" />
|
|
2
|
-
import { ApolloLink, Observable, type Operation, type NextLink } from '@apollo/client/core';
|
|
2
|
+
import { ApolloLink, Observable, type Operation, type NextLink, type FetchResult } from '@apollo/client/core';
|
|
3
3
|
/**
|
|
4
4
|
* Aborts the request if the timeout expires before the response is received.
|
|
5
5
|
*/
|
|
@@ -14,5 +14,5 @@ export default class TimeoutLink extends ApolloLink {
|
|
|
14
14
|
* @param statusCode - The HTTP status code to return when a timeout occurs. Default is 408 (Request Timeout).
|
|
15
15
|
*/
|
|
16
16
|
constructor(timeout?: number, statusCode?: number);
|
|
17
|
-
request(operation: Operation, forward: NextLink): Observable<
|
|
17
|
+
request(operation: Operation, forward: NextLink): Observable<FetchResult>;
|
|
18
18
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apollo-link-timeout",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"description": "Abort requests that take longer than a specified timeout period",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@apollo/client": "^3.0.0"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
|
-
"@apollo/client": "^3.
|
|
9
|
+
"@apollo/client": "^3.13.9",
|
|
10
10
|
"@types/jest": "^23.1.1",
|
|
11
11
|
"@types/node": "^10.3.4",
|
|
12
12
|
"graphql": "^15.3.0",
|
|
@@ -72,13 +72,17 @@
|
|
|
72
72
|
"moduleNameMapper": {
|
|
73
73
|
"(.+)\\.js": "$1"
|
|
74
74
|
},
|
|
75
|
-
"testEnvironment": "
|
|
75
|
+
"testEnvironment": "./__tests__/fixedEnvironment.js",
|
|
76
|
+
"transformIgnorePatterns": [
|
|
77
|
+
"__tests__/fixedEnvironment.js",
|
|
78
|
+
"/node_modules/"
|
|
79
|
+
],
|
|
76
80
|
"testPathIgnorePatterns": [
|
|
77
81
|
"__tests__/integration/",
|
|
78
82
|
"/node_modules/",
|
|
79
83
|
"/lib/"
|
|
80
84
|
],
|
|
81
|
-
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx
|
|
85
|
+
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$",
|
|
82
86
|
"transform": {
|
|
83
87
|
".(ts|tsx)": "ts-jest"
|
|
84
88
|
}
|
package/src/timeoutLink.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// note, this import is modified when building for ESM via `script/fix_apollo_import.mjs`
|
|
2
|
-
import { ApolloLink, Observable, type Operation, type NextLink } from '@apollo/client/core';
|
|
2
|
+
import { ApolloLink, Observable, type Operation, type NextLink, type FetchResult } from '@apollo/client/core';
|
|
3
3
|
import type { DefinitionNode } from 'graphql';
|
|
4
4
|
import TimeoutError from './TimeoutError.js';
|
|
5
5
|
|
|
@@ -25,13 +25,21 @@ export default class TimeoutLink extends ApolloLink {
|
|
|
25
25
|
this.statusCode = statusCode;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
public request(operation: Operation, forward: NextLink) {
|
|
28
|
+
public request(operation: Operation, forward: NextLink): Observable<FetchResult> {
|
|
29
29
|
let controller: AbortController;
|
|
30
30
|
let ourController: AbortController;
|
|
31
31
|
|
|
32
32
|
// override timeout from query context
|
|
33
33
|
const requestTimeout = operation.getContext().timeout || this.timeout;
|
|
34
34
|
|
|
35
|
+
const operationType = (operation.query.definitions as any).find(
|
|
36
|
+
(def: DefinitionNode) => def.kind === 'OperationDefinition'
|
|
37
|
+
).operation;
|
|
38
|
+
|
|
39
|
+
if (requestTimeout <= 0 || operationType === 'subscription') {
|
|
40
|
+
return forward(operation); // skip this link if timeout is zero or it's a subscription request
|
|
41
|
+
}
|
|
42
|
+
|
|
35
43
|
// add abort controller and signal object to fetchOptions if they don't already exist
|
|
36
44
|
if (typeof AbortController !== 'undefined') {
|
|
37
45
|
const context = operation.getContext();
|
|
@@ -46,17 +54,9 @@ export default class TimeoutLink extends ApolloLink {
|
|
|
46
54
|
|
|
47
55
|
const chainObservable = forward(operation); // observable for remaining link chain
|
|
48
56
|
|
|
49
|
-
const operationType = (operation.query.definitions as any).find(
|
|
50
|
-
(def: DefinitionNode) => def.kind === 'OperationDefinition'
|
|
51
|
-
).operation;
|
|
52
|
-
|
|
53
|
-
if (requestTimeout <= 0 || operationType === 'subscription') {
|
|
54
|
-
return chainObservable; // skip this link if timeout is zero or it's a subscription request
|
|
55
|
-
}
|
|
56
|
-
|
|
57
57
|
// create local observable with timeout functionality (unsubscibe from chain observable and
|
|
58
58
|
// return an error if the timeout expires before chain observable resolves)
|
|
59
|
-
const localObservable = new Observable(observer => {
|
|
59
|
+
const localObservable = new Observable<FetchResult>(observer => {
|
|
60
60
|
let timer: any;
|
|
61
61
|
|
|
62
62
|
// listen to chainObservable for result and pass to localObservable if received before timeout
|