@httptoolkit/subscriptions-transport-ws
Advanced tools
Comparing version 0.9.19 to 0.11.1
# Changelog | ||
## v0.11.0 (2021-11-02) | ||
- Support for `graphql@16` and bump minimal supported version to be `graphql@15.7.2`. As part of this change signatures for `ExecuteFunction` and `SubscribeFunction` were changed. <br/> | ||
[@IvanGoncharov](https://github.com/IvanGoncharov) in [#902](https://github.com/apollographql/subscriptions-transport-ws/pull/902) | ||
## v0.10.0 (2021-06-08) | ||
- Same contents as v0.9.19 (published before v0.9.19 before realizing it would be helpful if the new version was picked up by packages looking for `^0.9`). | ||
## v0.9.19 (2021-06-08) | ||
- Bump `ws` dependency to allow v6 and v7. Note that there are breaking changes in `ws` [`6.0.0`](https://github.com/websockets/ws/releases/tag/6.0.0) and [`7.0.0`](https://github.com/websockets/ws/releases/tag/7.0.0); for example, messages over 100MiB are rejected, and (in v7) the behavior of sending messages while the connection is starting or ending has changed. We are publishing this package to allow users of Apollo Server 2 to avoid seeing [this CVE](https://www.npmjs.com/advisories/1748) in their `npm audit`. However, note that (a) this CVE does not affect the subscriptions client, just the server and (b) Apollo Server 3 will remove its superficial integration with this package entirely. We encourage users of Apollo Server 2 to disable the integration with this unmaintained package via `new ApolloServer({subscriptions: false})`, and consider packages such as `graphql-ws` to power GraphQL subscriptions until such time as Apollo Server has more fully integrated subscriptions support. | ||
## v0.9.18 (2020-08-17) | ||
@@ -4,0 +18,0 @@ |
@@ -49,8 +49,10 @@ "use strict"; | ||
}; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
@@ -129,4 +131,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
this.client.onclose = null; | ||
this.client.onerror = null; | ||
this.client.onmessage = null; | ||
this.client.onerror = function () { }; | ||
this.client = null; | ||
@@ -232,3 +234,3 @@ this.eventEmitter.emit('disconnected'); | ||
}; | ||
queue(__spreadArrays(_this.middlewares), _this); | ||
queue(__spreadArray([], _this.middlewares, true), _this); | ||
}); | ||
@@ -343,5 +345,5 @@ }; | ||
} | ||
if ((!is_string_1.default(query) && !getOperationAST_1.getOperationAST(query, operationName)) || | ||
(operationName && !is_string_1.default(operationName)) || | ||
(variables && !is_object_1.default(variables))) { | ||
if ((!(0, is_string_1.default)(query) && !(0, getOperationAST_1.getOperationAST)(query, operationName)) || | ||
(operationName && !(0, is_string_1.default)(operationName)) || | ||
(variables && !(0, is_object_1.default)(variables))) { | ||
throw new Error('Incorrect option types. query must be a string or a document,' + | ||
@@ -352,3 +354,3 @@ '`operationName` must be a string, and `variables` must be an object.'); | ||
SubscriptionClient.prototype.buildMessage = function (id, type, payload) { | ||
var payloadToReturn = payload && payload.query ? __assign(__assign({}, payload), { query: typeof payload.query === 'string' ? payload.query : printer_1.print(payload.query) }) : | ||
var payloadToReturn = payload && payload.query ? __assign(__assign({}, payload), { query: typeof payload.query === 'string' ? payload.query : (0, printer_1.print)(payload.query) }) : | ||
payload; | ||
@@ -388,3 +390,3 @@ return { | ||
catch (e) { | ||
this.eventEmitter.emit('error', new Error("Message must be JSON-serializable. Got: " + message)); | ||
this.eventEmitter.emit('error', new Error("Message must be JSON-serializable. Got: ".concat(message))); | ||
} | ||
@@ -452,3 +454,3 @@ this.client.send(serializedMessage); | ||
var _this = this; | ||
this.client = new ((_a = this.wsImpl).bind.apply(_a, __spreadArrays([void 0, this.url, this.wsProtocols], this.wsOptionArguments)))(); | ||
this.client = new ((_a = this.wsImpl).bind.apply(_a, __spreadArray([void 0, this.url, this.wsProtocols], this.wsOptionArguments, false)))(); | ||
this.checkMaxConnectTimeout(); | ||
@@ -492,3 +494,3 @@ this.client.onopen = function () { return __awaiter(_this, void 0, void 0, function () { | ||
var data = _a.data; | ||
_this.processReceivedData(data); | ||
_this.processReceivedData(data.toString()); | ||
}; | ||
@@ -504,3 +506,3 @@ }; | ||
catch (e) { | ||
throw new Error("Message must be JSON-parseable. Got: " + receivedData); | ||
throw new Error("Message must be JSON-parseable. Got: ".concat(receivedData)); | ||
} | ||
@@ -507,0 +509,0 @@ if ([message_types_1.default.GQL_DATA, |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,5 +14,6 @@ if (k2 === undefined) k2 = k; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MessageTypes = void 0; | ||
__exportStar(require("./client"), exports); | ||
@@ -15,0 +20,0 @@ __exportStar(require("./server"), exports); |
@@ -16,3 +16,3 @@ "use strict"; | ||
var message_types_1 = require("../message-types"); | ||
exports.parseLegacyProtocolMessage = function (connectionContext, message) { | ||
var parseLegacyProtocolMessage = function (connectionContext, message) { | ||
var messageToReturn = message; | ||
@@ -73,2 +73,3 @@ switch (message.type) { | ||
}; | ||
exports.parseLegacyProtocolMessage = parseLegacyProtocolMessage; | ||
//# sourceMappingURL=parse-legacy-protocol.js.map |
/// <reference types="node" /> | ||
import * as WebSocket from 'ws'; | ||
import { ExecutionResult, GraphQLSchema, DocumentNode, ValidationContext, GraphQLFieldResolver } from 'graphql'; | ||
import { ExecutionResult, GraphQLSchema, DocumentNode, ValidationContext, ExecutionArgs, SubscriptionArgs } from 'graphql'; | ||
import { IncomingMessage } from 'http'; | ||
@@ -40,8 +40,4 @@ export declare type ExecutionIterator = AsyncIterator<ExecutionResult>; | ||
} | ||
export declare type ExecuteFunction = (schema: GraphQLSchema, document: DocumentNode, rootValue?: any, contextValue?: any, variableValues?: { | ||
[key: string]: any; | ||
}, operationName?: string, fieldResolver?: GraphQLFieldResolver<any, any>) => ExecutionResult | Promise<ExecutionResult> | AsyncIterator<ExecutionResult>; | ||
export declare type SubscribeFunction = (schema: GraphQLSchema, document: DocumentNode, rootValue?: any, contextValue?: any, variableValues?: { | ||
[key: string]: any; | ||
}, operationName?: string, fieldResolver?: GraphQLFieldResolver<any, any>, subscribeFieldResolver?: GraphQLFieldResolver<any, any>) => AsyncIterator<ExecutionResult> | Promise<AsyncIterator<ExecutionResult> | ExecutionResult>; | ||
export declare type ExecuteFunction = (args: ExecutionArgs) => ExecutionResult | Promise<ExecutionResult> | AsyncIterator<ExecutionResult>; | ||
export declare type SubscribeFunction = (args: SubscriptionArgs) => AsyncIterator<ExecutionResult> | Promise<AsyncIterator<ExecutionResult> | ExecutionResult>; | ||
export interface ServerOptions { | ||
@@ -48,0 +44,0 @@ rootValue?: any; |
@@ -64,2 +64,3 @@ "use strict"; | ||
_this.wsServer.close(); | ||
_this.wsServer.clients.forEach(function (ws) { return ws.terminate(); }); | ||
}; | ||
@@ -112,3 +113,3 @@ } | ||
try { | ||
parsedMessage = parse_legacy_protocol_1.parseLegacyProtocolMessage(connectionContext, JSON.parse(message)); | ||
parsedMessage = (0, parse_legacy_protocol_1.parseLegacyProtocolMessage)(connectionContext, JSON.parse(message.toString())); | ||
} | ||
@@ -167,3 +168,3 @@ catch (e) { | ||
operationName: parsedMessage.payload.operationName, | ||
context: is_object_1.default(initResult) ? Object.assign(Object.create(Object.getPrototypeOf(initResult)), initResult) : {}, | ||
context: (0, is_object_1.default)(initResult) ? Object.assign(Object.create(Object.getPrototypeOf(initResult)), initResult) : {}, | ||
formatResponse: undefined, | ||
@@ -175,3 +176,3 @@ formatError: undefined, | ||
var promisedParams = Promise.resolve(baseParams); | ||
connectionContext.operations[opId] = empty_iterable_1.createEmptyIterable(); | ||
connectionContext.operations[opId] = (0, empty_iterable_1.createEmptyIterable)(); | ||
if (_this.onOperation) { | ||
@@ -193,5 +194,5 @@ var messageForCallback = parsedMessage; | ||
} | ||
var document = typeof baseParams.query !== 'string' ? baseParams.query : graphql_1.parse(baseParams.query); | ||
var document = typeof baseParams.query !== 'string' ? baseParams.query : (0, graphql_1.parse)(baseParams.query); | ||
var executionPromise; | ||
var validationErrors = graphql_1.validate(params.schema, document, _this.specifiedRules); | ||
var validationErrors = (0, graphql_1.validate)(params.schema, document, _this.specifiedRules); | ||
if (validationErrors.length > 0) { | ||
@@ -202,10 +203,17 @@ executionPromise = Promise.resolve({ errors: validationErrors }); | ||
var executor = _this.execute; | ||
if (_this.subscribe && is_subscriptions_1.isASubscriptionOperation(document, params.operationName)) { | ||
if (_this.subscribe && (0, is_subscriptions_1.isASubscriptionOperation)(document, params.operationName)) { | ||
executor = _this.subscribe; | ||
} | ||
executionPromise = Promise.resolve(executor(params.schema, document, _this.rootValue, params.context, params.variables, params.operationName)); | ||
executionPromise = Promise.resolve(executor({ | ||
schema: params.schema, | ||
document: document, | ||
rootValue: _this.rootValue, | ||
contextValue: params.context, | ||
variableValues: params.variables, | ||
operationName: params.operationName, | ||
})); | ||
} | ||
return executionPromise.then(function (executionResult) { return ({ | ||
executionIterable: iterall_1.isAsyncIterable(executionResult) ? | ||
executionResult : iterall_1.createAsyncIterator([executionResult]), | ||
executionIterable: (0, iterall_1.isAsyncIterable)(executionResult) ? | ||
executionResult : (0, iterall_1.createAsyncIterator)([executionResult]), | ||
params: params, | ||
@@ -215,3 +223,3 @@ }); }); | ||
var executionIterable = _a.executionIterable, params = _a.params; | ||
iterall_1.forAwaitEach(executionIterable, function (value) { | ||
(0, iterall_1.forAwaitEach)(executionIterable, function (value) { | ||
var result = value; | ||
@@ -283,3 +291,3 @@ if (params.formatResponse) { | ||
SubscriptionServer.prototype.sendMessage = function (connectionContext, opId, type, payload) { | ||
var parsedMessage = parse_legacy_protocol_1.parseLegacyProtocolMessage(connectionContext, { | ||
var parsedMessage = (0, parse_legacy_protocol_1.parseLegacyProtocolMessage)(connectionContext, { | ||
type: type, | ||
@@ -286,0 +294,0 @@ id: opId, |
@@ -5,3 +5,3 @@ "use strict"; | ||
var iterall_1 = require("iterall"); | ||
exports.createEmptyIterable = function () { | ||
var createEmptyIterable = function () { | ||
var _a; | ||
@@ -24,2 +24,3 @@ return _a = { | ||
}; | ||
exports.createEmptyIterable = createEmptyIterable; | ||
//# sourceMappingURL=empty-iterable.js.map |
@@ -5,6 +5,7 @@ "use strict"; | ||
var graphql_1 = require("graphql"); | ||
exports.isASubscriptionOperation = function (document, operationName) { | ||
var operationAST = graphql_1.getOperationAST(document, operationName); | ||
var isASubscriptionOperation = function (document, operationName) { | ||
var operationAST = (0, graphql_1.getOperationAST)(document, operationName); | ||
return !!operationAST && operationAST.operation === 'subscription'; | ||
}; | ||
exports.isASubscriptionOperation = isASubscriptionOperation; | ||
//# sourceMappingURL=is-subscriptions.js.map |
{ | ||
"name": "@httptoolkit/subscriptions-transport-ws", | ||
"version": "0.9.19", | ||
"version": "0.11.1", | ||
"description": "A websocket transport for GraphQL subscriptions", | ||
@@ -16,3 +16,3 @@ "main": "dist/index.js", | ||
"symbol-observable": "^1.0.4", | ||
"ws": "^7.4.6" | ||
"ws": "^8.8.0" | ||
}, | ||
@@ -34,7 +34,6 @@ "scripts": { | ||
"peerDependencies": { | ||
"graphql": ">=0.10.0" | ||
"graphql": "^15.7.2 || ^16.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.0.0", | ||
"@types/graphql": "^14.0.0", | ||
"@types/is-promise": "^2.1.0", | ||
@@ -47,4 +46,4 @@ "@types/lodash": "^4.14.109", | ||
"chai": "^4.0.2", | ||
"graphql": "^15.3.0", | ||
"graphql-subscriptions": "^1.0.0", | ||
"graphql": "16.0.0", | ||
"graphql-subscriptions": "^2.0.0", | ||
"istanbul": "^1.0.0-alpha.2", | ||
@@ -58,3 +57,3 @@ "lodash": "^4.17.1", | ||
"tslint": "^5.10.0", | ||
"typescript": "^3.9.6", | ||
"typescript": "^4.1.0", | ||
"webpack": "^3.1.0" | ||
@@ -61,0 +60,0 @@ }, |
@@ -1,11 +0,7 @@ | ||
# @httptoolkit/graphql-ws | ||
# @httptoolkit/subscriptions-transport-ws | ||
_This is a fork of subscriptions-transport-ws, updating ws to fix security issues. This is a quick fix, and won't be maintained in future_ | ||
_This is a fork of subscriptions-transport-ws, updating ws to fix security issues. This is a quick fix, and won't be maintained for general use outside [Mockttp](https://github.com/httptoolkit/mockttp) in future_ | ||
The `subscriptions-transport-ws` library is not being actively maintained. It is recommended that you use the [graphql-ws](https://github.com/enisdenjo/graphql-ws) library instead. For details read the [GraphQL over WebSockets](https://the-guild.dev/blog/graphql-over-websockets) announcement. | ||
[![npm version](https://badge.fury.io/js/subscriptions-transport-ws.svg)](https://badge.fury.io/js/@httptoolkit/subscriptions-transport-ws) [![GitHub license](https://img.shields.io/github/license/httptoolkit/subscriptions-transport-ws.svg)](https://github.com/httptoolkit/subscriptions-transport-ws/blob/license/LICENSE) | ||
# subscriptions-transport-ws | ||
[![npm version](https://badge.fury.io/js/subscriptions-transport-ws.svg)](https://badge.fury.io/js/subscriptions-transport-ws) [![GitHub license](https://img.shields.io/github/license/apollostack/subscriptions-transport-ws.svg)](https://github.com/apollostack/subscriptions-transport-ws/blob/license/LICENSE) | ||
**(Work in progress!)** | ||
@@ -17,4 +13,2 @@ | ||
See [GitHunt-API](https://github.com/apollostack/GitHunt-API) and [GitHunt-React](https://github.com/apollostack/GitHunt-React) for an example server and client integration. | ||
# Getting Started | ||
@@ -25,6 +19,6 @@ | ||
Using Yarn: | ||
$ yarn add subscriptions-transport-ws | ||
$ yarn add @httptoolkit/subscriptions-transport-ws | ||
Or, using NPM: | ||
$ npm install --save subscriptions-transport-ws | ||
$ npm install --save @httptoolkit/subscriptions-transport-ws | ||
@@ -49,3 +43,3 @@ > Note that you need to use this package on both GraphQL client and server. | ||
import { createServer } from 'http'; | ||
import { SubscriptionServer } from 'subscriptions-transport-ws'; | ||
import { SubscriptionServer } from '@httptoolkit/subscriptions-transport-ws'; | ||
import { execute, subscribe } from 'graphql'; | ||
@@ -97,3 +91,3 @@ import { schema } from './my-schema'; | ||
```js | ||
import { SubscriptionClient } from 'subscriptions-transport-ws'; | ||
import { SubscriptionClient } from '@httptoolkit/subscriptions-transport-ws'; | ||
import ApolloClient from 'apollo-client'; | ||
@@ -118,3 +112,3 @@ | ||
```js | ||
import {SubscriptionClient, addGraphQLSubscriptions} from 'subscriptions-transport-ws'; | ||
import {SubscriptionClient, addGraphQLSubscriptions} from '@httptoolkit/subscriptions-transport-ws'; | ||
import ApolloClient, {createNetworkInterface} from 'apollo-client'; | ||
@@ -187,3 +181,3 @@ | ||
``` | ||
https://unpkg.com/subscriptions-transport-ws@VERSION/browser/client.js | ||
https://unpkg.com/@httptoolkit/subscriptions-transport-ws@VERSION/browser/client.js | ||
``` | ||
@@ -212,3 +206,3 @@ | ||
```html | ||
<script src="//unpkg.com/subscriptions-transport-ws@0.5.4/browser/client.js"></script> | ||
<script src="//unpkg.com/@httptoolkit/subscriptions-transport-ws@0.5.4/browser/client.js"></script> | ||
<script src="//unpkg.com/graphiql-subscriptions-fetcher@0.0.2/browser/client.js"></script> | ||
@@ -215,0 +209,0 @@ ``` |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
335115
20
48
4019
332