@graphql-tools/executor-legacy-ws 1.0.0 → 1.0.1-rc-20230612101309-a46efd88
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/cjs/index.js +13 -7
- package/esm/index.js +11 -6
- package/package.json +1 -1
package/cjs/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildWSLegacyExecutor = exports.LEGACY_WS = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const utils_1 = require("@graphql-tools/utils");
|
|
5
6
|
const graphql_1 = require("graphql");
|
|
7
|
+
const isomorphic_ws_1 = tslib_1.__importDefault(require("isomorphic-ws"));
|
|
6
8
|
var LEGACY_WS;
|
|
7
9
|
(function (LEGACY_WS) {
|
|
8
10
|
LEGACY_WS["CONNECTION_INIT"] = "connection_init";
|
|
@@ -15,9 +17,8 @@ var LEGACY_WS;
|
|
|
15
17
|
LEGACY_WS["DATA"] = "data";
|
|
16
18
|
LEGACY_WS["ERROR"] = "error";
|
|
17
19
|
LEGACY_WS["COMPLETE"] = "complete";
|
|
18
|
-
})(LEGACY_WS
|
|
20
|
+
})(LEGACY_WS || (exports.LEGACY_WS = LEGACY_WS = {}));
|
|
19
21
|
function buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, options) {
|
|
20
|
-
const observerById = new Map();
|
|
21
22
|
let websocket = null;
|
|
22
23
|
const ensureWebsocket = () => {
|
|
23
24
|
websocket = new WebSocketImpl(subscriptionsEndpoint, 'graphql-ws', {
|
|
@@ -41,9 +42,12 @@ function buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, options) {
|
|
|
41
42
|
payload,
|
|
42
43
|
}));
|
|
43
44
|
};
|
|
45
|
+
websocket.onclose = () => {
|
|
46
|
+
websocket = null;
|
|
47
|
+
};
|
|
44
48
|
};
|
|
45
49
|
const cleanupWebsocket = () => {
|
|
46
|
-
if (websocket != null
|
|
50
|
+
if (websocket != null) {
|
|
47
51
|
websocket.send(JSON.stringify({
|
|
48
52
|
type: LEGACY_WS.CONNECTION_TERMINATE,
|
|
49
53
|
}));
|
|
@@ -103,10 +107,12 @@ function buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, options) {
|
|
|
103
107
|
};
|
|
104
108
|
return {
|
|
105
109
|
unsubscribe: () => {
|
|
106
|
-
websocket?.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
if (websocket?.readyState === isomorphic_ws_1.default.OPEN) {
|
|
111
|
+
websocket?.send(JSON.stringify({
|
|
112
|
+
type: LEGACY_WS.STOP,
|
|
113
|
+
id,
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
110
116
|
cleanupWebsocket();
|
|
111
117
|
},
|
|
112
118
|
};
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { observableToAsyncIterable } from '@graphql-tools/utils';
|
|
2
2
|
import { print } from 'graphql';
|
|
3
|
+
import WebSocket from 'isomorphic-ws';
|
|
3
4
|
export var LEGACY_WS;
|
|
4
5
|
(function (LEGACY_WS) {
|
|
5
6
|
LEGACY_WS["CONNECTION_INIT"] = "connection_init";
|
|
@@ -14,7 +15,6 @@ export var LEGACY_WS;
|
|
|
14
15
|
LEGACY_WS["COMPLETE"] = "complete";
|
|
15
16
|
})(LEGACY_WS || (LEGACY_WS = {}));
|
|
16
17
|
export function buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, options) {
|
|
17
|
-
const observerById = new Map();
|
|
18
18
|
let websocket = null;
|
|
19
19
|
const ensureWebsocket = () => {
|
|
20
20
|
websocket = new WebSocketImpl(subscriptionsEndpoint, 'graphql-ws', {
|
|
@@ -38,9 +38,12 @@ export function buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, opti
|
|
|
38
38
|
payload,
|
|
39
39
|
}));
|
|
40
40
|
};
|
|
41
|
+
websocket.onclose = () => {
|
|
42
|
+
websocket = null;
|
|
43
|
+
};
|
|
41
44
|
};
|
|
42
45
|
const cleanupWebsocket = () => {
|
|
43
|
-
if (websocket != null
|
|
46
|
+
if (websocket != null) {
|
|
44
47
|
websocket.send(JSON.stringify({
|
|
45
48
|
type: LEGACY_WS.CONNECTION_TERMINATE,
|
|
46
49
|
}));
|
|
@@ -100,10 +103,12 @@ export function buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, opti
|
|
|
100
103
|
};
|
|
101
104
|
return {
|
|
102
105
|
unsubscribe: () => {
|
|
103
|
-
websocket?.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
if (websocket?.readyState === WebSocket.OPEN) {
|
|
107
|
+
websocket?.send(JSON.stringify({
|
|
108
|
+
type: LEGACY_WS.STOP,
|
|
109
|
+
id,
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
107
112
|
cleanupWebsocket();
|
|
108
113
|
},
|
|
109
114
|
};
|
package/package.json
CHANGED