Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Support for graphql@16 and bump minimal supported version (#902)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Nov 2, 2021
1 parent 231c1b0 commit a8bbabf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# 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`).
Expand Down
7 changes: 3 additions & 4 deletions package.json
Expand Up @@ -30,19 +30,18 @@
"prepublishOnly": "npm run clean && npm run compile && npm run browser-compile"
},
"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",
"@types/lodash": "^4.14.109",
"@types/mocha": "^5.2.5",
"@types/node": "^8.0.8",
"@types/sinon": "^5.0.1",
"@types/ws": "^5.1.2",
"chai": "^4.0.2",
"graphql": "^15.3.0",
"graphql": "16.0.0",
"graphql-subscriptions": "^1.0.0",
"istanbul": "^1.0.0-alpha.2",
"lodash": "^4.17.1",
Expand All @@ -52,7 +51,7 @@
"rimraf": "^2.6.1",
"sinon": "^6.1.4",
"tslint": "^5.10.0",
"typescript": "^3.9.6",
"typescript": "^4.1.0",
"webpack": "^3.1.0"
},
"typings": "dist/index.d.ts",
Expand Down
47 changes: 20 additions & 27 deletions src/server.ts
Expand Up @@ -12,6 +12,8 @@ import {
ValidationContext,
specifiedRules,
GraphQLFieldResolver,
ExecutionArgs,
SubscriptionArgs,
} from 'graphql';
import { createEmptyIterable } from './utils/empty-iterable';
import { createAsyncIterator, forAwaitEach, isAsyncIterable } from 'iterall';
Expand Down Expand Up @@ -55,27 +57,14 @@ export interface OperationMessage {
type: string;
}

export 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 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 type ExecuteFunction = (args: ExecutionArgs) =>
| ExecutionResult
| Promise<ExecutionResult>
| AsyncIterator<ExecutionResult>;

export type SubscribeFunction = (args: SubscriptionArgs) =>
| AsyncIterator<ExecutionResult>
| Promise<AsyncIterator<ExecutionResult> | ExecutionResult>;

export interface ServerOptions {
rootValue?: any;
Expand Down Expand Up @@ -356,12 +345,16 @@ export class SubscriptionServer {
if (this.subscribe && 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,
rootValue: this.rootValue,
contextValue: params.context,
variableValues: params.variables,
operationName: params.operationName,
}),
);
}

return executionPromise.then((executionResult) => ({
Expand Down
6 changes: 3 additions & 3 deletions src/test/tests.ts
Expand Up @@ -792,7 +792,7 @@ describe('Client', function () {
try {
sub.unsubscribe();
expect(Object.keys(client.operations).length).to.equals(0);
resolve();
resolve(undefined);
} catch (e) {
reject(e);
}
Expand Down Expand Up @@ -2643,7 +2643,7 @@ describe('Client<->Server Flow', () => {
assert(sRes.errors === undefined, 'unexpected error from 1st subscription');
assert(sRes.data, 'unexpected null from 1st subscription result');
expect(Object.keys(client['operations']).length).to.eq(1);
expect(sRes.data.user.id).to.eq('3');
expect(sRes.data.user).to.include({ id: '3' });
firstSubscriptionSpy();

firstSub.unsubscribe();
Expand All @@ -2660,7 +2660,7 @@ describe('Client<->Server Flow', () => {
next: (s2Res) => {
assert(s2Res.errors === undefined, 'unexpected error from 2nd subscription');
assert(s2Res.data !== null, 'unexpected null from 2nd subscription result');
expect(s2Res.data.user.id).to.eq('1');
expect(s2Res.data.user).to.include({ id: '1' });
expect(Object.keys(client['operations']).length).to.eq(1);
expect(firstSubscriptionSpy.callCount).to.eq(1);

Expand Down

0 comments on commit a8bbabf

Please sign in to comment.