Socket
Socket
Sign inDemoInstall

graphql-ws

Package Overview
Dependencies
11
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.6 to 0.1.7

4

dist/BinaryReceiver.d.ts
/// <reference types="node" />
import { Readable, ReadableOptions } from 'stream';
import * as WebSocket from 'ws';
import { SocketLike } from './common';
export { Readable, ReadableOptions };

@@ -9,3 +9,3 @@ export interface BinaryReceiverOptions {

fileId: number;
socket: WebSocket;
socket: SocketLike;
}

@@ -12,0 +12,0 @@ export declare class BinaryReceiver extends Readable {

@@ -73,3 +73,3 @@ "use strict";

else {
if (!this.push(payload)) {
if (!this.push(Buffer.from(payload))) {
const read = new Promise(resolve => this.events.once('read', resolve));

@@ -76,0 +76,0 @@ yield read;

/// <reference types="node" />
import { Writable, WritableOptions } from 'stream';
import * as WebSocket from 'ws';
import { SocketLike } from './common';
export { Writable, WritableOptions };

@@ -8,3 +8,3 @@ export interface BinarySenderOptions {

fileId: number;
socket: WebSocket;
socket: SocketLike;
}

@@ -11,0 +11,0 @@ export declare class BinarySender extends Writable {

@@ -5,2 +5,3 @@ import { ListenerFn } from 'eventemitter3';

import { Binary } from './Binary';
import { SocketWrapper } from './common';
export { Readable, Writable, Buffer } from 'readable-stream';

@@ -53,3 +54,3 @@ export { Binary };

export declare class SubscriptionClient {
client: any;
client: SocketWrapper;
operations: Operations;

@@ -106,3 +107,3 @@ private filesOut;

private checkMaxConnectTimeout();
private patchSocket();
private patchSocket(socket);
private connect();

@@ -109,0 +110,0 @@ private processReceivedData(receivedData);

@@ -335,7 +335,6 @@ "use strict";

}
patchSocket() {
this.client.removeListener = this.client.removeEventListener;
let sockSend = this.client.send;
sockSend = sockSend.bind(this.client);
this.client.send = (data, callback) => {
patchSocket(socket) {
socket.on = (event, cb) => socket.addEventListener(event, ({ data }) => cb(data));
const sockSend = socket.send.bind(socket);
socket.send = (data, callback) => {
try {

@@ -358,7 +357,8 @@ sockSend(data);

connect() {
this.client = new this.wsImpl(this.url, protocol_1.GRAPHQL_WS);
this.client.binaryType = 'arraybuffer';
this.patchSocket();
const socket = new this.wsImpl(this.url, protocol_1.GRAPHQL_WS);
this.patchSocket(socket);
this.client = new common_1.SocketWrapper(socket);
this.client.getSocket().binaryType = 'arraybuffer';
this.checkMaxConnectTimeout();
this.client.onopen = () => {
this.client.getSocket().onopen = () => {
this.clearMaxConnectTimeout();

@@ -371,3 +371,3 @@ this.closedByUser = false;

};
this.client.onclose = () => {
this.client.getSocket().onclose = () => {
if (!this.closedByUser) {

@@ -377,7 +377,7 @@ this.close(false, false);

};
this.client.onerror = () => {
this.client.getSocket().onerror = () => {
};
this.client.onmessage = ({ data }) => {
this.client.on('message', (data) => {
this.processReceivedData(data);
};
});
}

@@ -384,0 +384,0 @@ processReceivedData(receivedData) {

@@ -6,2 +6,30 @@ import { Binary } from './Binary';

}
export declare class SocketWrapper implements SocketLike {
private events;
private socket;
constructor(socket: any);
send(data: any, cb?: (err: Error) => void): void;
readonly readyState: number;
close(code?: number, data?: any): void;
getSocket(): any;
on(event: 'message', cb: (data: any, flags: {
binary: boolean;
}) => void): this;
once(event: 'message', cb: (data: any, flags: {
binary: boolean;
}) => void): this;
removeListener(event: 'message', cb: (data: any, flags: {
binary: boolean;
}) => void): this;
removeEventListener(event: 'message', cb: (data: any, flags: {
binary: boolean;
}) => void): this;
private onMessage(message);
}
export interface SocketLike {
send: (data: any, cb?: (err: Error) => void) => void;
on: Function;
once: Function;
removeListener: Function;
}
export declare function repeatPromise(promise: () => Promise<boolean>): any;

@@ -8,0 +36,0 @@ export declare function extractIncomingFiles(opId: number, socket: any, obj?: {

@@ -6,2 +6,42 @@ "use strict";

const message_type_1 = require("./message-type");
const events_1 = require("events");
class SocketWrapper {
constructor(socket) {
this.events = new events_1.EventEmitter();
this.socket = socket;
this.socket.on('message', this.onMessage.bind(this));
}
send(data, cb) {
this.socket.send(data, cb);
}
get readyState() {
return this.socket.readyState;
}
close(code, data) {
this.socket.close(code, data);
}
getSocket() {
return this.socket;
}
on(event, cb) {
this.events.on('message', cb);
return this;
}
once(event, cb) {
this.events.once('message', cb);
return this;
}
removeListener(event, cb) {
this.events.removeListener('message', cb);
return this;
}
removeEventListener(event, cb) {
this.events.removeListener('message', cb);
return this;
}
onMessage(message) {
this.events.emit('message', message);
}
}
exports.SocketWrapper = SocketWrapper;
function repeatPromise(promise) {

@@ -8,0 +48,0 @@ return promise().then((repeat) => repeat && repeatPromise(promise));

/// <reference types="node" />
import * as WebSocket from 'ws';
import * as WebSocket from 'uws';
import { EventEmitter } from 'events';
import { ExecutionResult, GraphQLSchema, DocumentNode, ValidationContext, GraphQLFieldResolver } from 'graphql';
import { Binary } from './Binary';
import { FileRequestPayload } from './common';
import { FileRequestPayload, SocketWrapper } from './common';
export declare type ExecutionIterator = AsyncIterator<ExecutionResult>;

@@ -21,3 +21,3 @@ export interface ExecutionParams<TContext = any> {

initPromise?: Promise<any>;
socket: WebSocket;
socket: SocketWrapper;
filesIn: {

@@ -24,0 +24,0 @@ [id: number]: Binary[];

@@ -11,3 +11,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const WebSocket = require("ws");
const WebSocket = require("uws");
const events_1 = require("events");

@@ -55,7 +55,4 @@ const message_type_1 = require("./message-type");

this.wsServer = new WebSocket.Server(socketOptions || {});
const connectionHandler = ((socket, request) => {
socket.upgradeReq = request;
socket.binaryType = 'arraybuffer';
if (socket.protocol === undefined ||
(socket.protocol.indexOf(protocol_1.GRAPHQL_WS) === -1)) {
const connectionHandler = ((socket) => {
if (socket.upgradeReq.headers['sec-websocket-protocol'] !== protocol_1.GRAPHQL_WS) {
socket.close(1002);

@@ -65,3 +62,3 @@ return;

const connectionContext = Object.create(null);
connectionContext.socket = socket;
connectionContext.socket = new common_1.SocketWrapper(socket);
connectionContext.operations = {};

@@ -95,3 +92,3 @@ connectionContext.filesIn = {};

socket.on('close', connectionClosedHandler);
socket.on('message', this.onMessage(connectionContext));
connectionContext.socket.on('message', this.onMessage(connectionContext));
});

@@ -98,0 +95,0 @@ this.wsServer.on('connection', connectionHandler);

{
"name": "graphql-ws",
"version": "0.1.6",
"version": "0.1.7",
"description": "WebSocket transport for GraphQL",

@@ -21,3 +21,3 @@ "main": "dist/index.js",

"symbol-observable": "^1.0.4",
"ws": "^3.0.0"
"uws": "^8.14.1"
},

@@ -48,3 +48,3 @@ "scripts": {

"@types/sinon": "^2.3.0",
"@types/ws": "^3.0.0",
"@types/uws": "^0.13.0",
"chai": "^4.0.2",

@@ -51,0 +51,0 @@ "graphql": "^0.11.3",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc