Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-tools/executor-legacy-ws

Package Overview
Dependencies
Maintainers
3
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/executor-legacy-ws - npm Package Compare versions

Comparing version 1.0.1-rc-20230612101309-a46efd88 to 1.0.1-rc-20230612102029-16c7ce78

81

cjs/index.js

@@ -23,27 +23,36 @@ "use strict";

let websocket = null;
const ensureWebsocket = () => {
websocket = new WebSocketImpl(subscriptionsEndpoint, 'graphql-ws', {
followRedirects: true,
headers: options?.headers,
rejectUnauthorized: false,
skipUTF8Validation: true,
});
websocket.onopen = () => {
let payload = {};
switch (typeof options?.connectionParams) {
case 'function':
payload = options?.connectionParams();
break;
case 'object':
payload = options?.connectionParams;
break;
}
websocket.send(JSON.stringify({
type: LEGACY_WS.CONNECTION_INIT,
payload,
}));
};
websocket.onclose = () => {
websocket = null;
};
const ensureWebsocket = (errorHandler = err => console.error(err)) => {
if (websocket == null || websocket.readyState !== isomorphic_ws_1.default.OPEN) {
websocket = new WebSocketImpl(subscriptionsEndpoint, 'graphql-ws', {
followRedirects: true,
headers: options?.headers,
rejectUnauthorized: false,
skipUTF8Validation: true,
});
websocket.onopen = () => {
let payload = {};
switch (typeof options?.connectionParams) {
case 'function':
payload = options?.connectionParams();
break;
case 'object':
payload = options?.connectionParams;
break;
}
websocket.send(JSON.stringify({
type: LEGACY_WS.CONNECTION_INIT,
payload,
}), (error) => {
if (error) {
errorHandler(error);
}
});
};
websocket.onerror = event => {
errorHandler(event.error);
};
websocket.onclose = () => {
websocket = null;
};
}
};

@@ -63,2 +72,5 @@ const cleanupWebsocket = () => {

subscribe(observer) {
function errorHandler(err) {
observer.error(err);
}
ensureWebsocket();

@@ -83,3 +95,7 @@ if (websocket == null) {

},
}));
}), (error) => {
if (error) {
errorHandler(error);
}
});
break;

@@ -99,8 +115,11 @@ }

case LEGACY_WS.COMPLETE: {
if (websocket == null) {
throw new Error(`WebSocket connection is not found!`);
if (websocket != null) {
websocket.send(JSON.stringify({
type: LEGACY_WS.CONNECTION_TERMINATE,
}), (error) => {
if (error) {
errorHandler(error);
}
});
}
websocket.send(JSON.stringify({
type: LEGACY_WS.CONNECTION_TERMINATE,
}));
observer.complete();

@@ -107,0 +126,0 @@ cleanupWebsocket();

@@ -19,27 +19,36 @@ import { observableToAsyncIterable } from '@graphql-tools/utils';

let websocket = null;
const ensureWebsocket = () => {
websocket = new WebSocketImpl(subscriptionsEndpoint, 'graphql-ws', {
followRedirects: true,
headers: options?.headers,
rejectUnauthorized: false,
skipUTF8Validation: true,
});
websocket.onopen = () => {
let payload = {};
switch (typeof options?.connectionParams) {
case 'function':
payload = options?.connectionParams();
break;
case 'object':
payload = options?.connectionParams;
break;
}
websocket.send(JSON.stringify({
type: LEGACY_WS.CONNECTION_INIT,
payload,
}));
};
websocket.onclose = () => {
websocket = null;
};
const ensureWebsocket = (errorHandler = err => console.error(err)) => {
if (websocket == null || websocket.readyState !== WebSocket.OPEN) {
websocket = new WebSocketImpl(subscriptionsEndpoint, 'graphql-ws', {
followRedirects: true,
headers: options?.headers,
rejectUnauthorized: false,
skipUTF8Validation: true,
});
websocket.onopen = () => {
let payload = {};
switch (typeof options?.connectionParams) {
case 'function':
payload = options?.connectionParams();
break;
case 'object':
payload = options?.connectionParams;
break;
}
websocket.send(JSON.stringify({
type: LEGACY_WS.CONNECTION_INIT,
payload,
}), (error) => {
if (error) {
errorHandler(error);
}
});
};
websocket.onerror = event => {
errorHandler(event.error);
};
websocket.onclose = () => {
websocket = null;
};
}
};

@@ -59,2 +68,5 @@ const cleanupWebsocket = () => {

subscribe(observer) {
function errorHandler(err) {
observer.error(err);
}
ensureWebsocket();

@@ -79,3 +91,7 @@ if (websocket == null) {

},
}));
}), (error) => {
if (error) {
errorHandler(error);
}
});
break;

@@ -95,8 +111,11 @@ }

case LEGACY_WS.COMPLETE: {
if (websocket == null) {
throw new Error(`WebSocket connection is not found!`);
if (websocket != null) {
websocket.send(JSON.stringify({
type: LEGACY_WS.CONNECTION_TERMINATE,
}), (error) => {
if (error) {
errorHandler(error);
}
});
}
websocket.send(JSON.stringify({
type: LEGACY_WS.CONNECTION_TERMINATE,
}));
observer.complete();

@@ -103,0 +122,0 @@ cleanupWebsocket();

{
"name": "@graphql-tools/executor-legacy-ws",
"version": "1.0.1-rc-20230612101309-a46efd88",
"version": "1.0.1-rc-20230612102029-16c7ce78",
"description": "A set of utils for faster development of GraphQL tools",

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

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