Skip to content

Commit 808b463

Browse files
YOUR_NAMEYOUR_NAME
authored andcommitted
subscription fix
1 parent e8d1c0b commit 808b463

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed

examples/typescript-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-node",
3-
"version": "3.1.4",
3+
"version": "3.1.5",
44
"description": "",
55
"private": true,
66
"main": "index.js",

packages/graphql-zeus-core/TreeToTS/functions/apiSSESubscription/sse.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { chainOptions } from '@/TreeToTS/functions/new/models';
22

3-
43
export const apiSubscriptionSSE = (options: chainOptions) => (query: string, variables?: Record<string, unknown>) => {
54
const url = options[0];
65
const fetchOptions = options[1] || {};
@@ -105,12 +104,18 @@ export const apiSubscriptionSSE = (options: chainOptions) => (query: string, var
105104
startStream();
106105
},
107106
close: () => {
107+
// Cancel the reader first (if it exists) to gracefully close the stream
108+
if (reader) {
109+
reader.cancel().catch(() => {
110+
// Ignore cancel errors - stream may already be closed
111+
});
112+
reader = null;
113+
}
114+
// Then abort the controller
108115
if (abortController) {
109116
abortController.abort();
110-
}
111-
if (reader) {
112-
reader.cancel();
117+
abortController = null;
113118
}
114119
},
115120
};
116-
};
121+
};

packages/graphql-zeus-core/TreeToTS/functions/generated.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ export const SubscriptionThunderSSE =
233233
Zeus(operation, o, {
234234
operationOptions: ops,
235235
scalars: options?.scalars,
236-
}), ops?.variables
236+
}),
237+
ops?.variables,
237238
) as SubscriptionToGraphQLSSE<Z, GraphQLTypes[R], CombinedSCLR>;
238239
if (returnedFunction?.on && options?.scalars) {
239240
const wrapped = returnedFunction.on;
@@ -474,7 +475,7 @@ export class GraphQLError extends Error {
474475
return 'GraphQL Response Error';
475476
}
476477
}
477-
export type GenericOperation<O> = O extends keyof typeof Ops ? typeof Ops[O] : never;
478+
export type GenericOperation<O> = O extends keyof typeof Ops ? (typeof Ops)[O] : never;
478479
export type ThunderGraphQLOptions<SCLR extends ScalarDefinition> = {
479480
scalars?: SCLR | ScalarCoders;
480481
};
@@ -1108,11 +1109,17 @@ export const sseFunctions = {
11081109
startStream();
11091110
},
11101111
close: () => {
1112+
// Cancel the reader first (if it exists) to gracefully close the stream
1113+
if (reader) {
1114+
reader.cancel().catch(() => {
1115+
// Ignore cancel errors - stream may already be closed
1116+
});
1117+
reader = null;
1118+
}
1119+
// Then abort the controller
11111120
if (abortController) {
11121121
abortController.abort();
1113-
}
1114-
if (reader) {
1115-
reader.cancel();
1122+
abortController = null;
11161123
}
11171124
},
11181125
};

packages/graphql-zeus-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-zeus-core",
3-
"version": "7.1.5",
3+
"version": "7.1.6",
44
"private": false,
55
"main": "./lib/index.js",
66
"author": "GraphQL Editor, Artur Czemiel",

packages/graphql-zeus-jsonschema/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-zeus-jsonschema",
3-
"version": "7.1.5",
3+
"version": "7.1.6",
44
"private": false,
55
"main": "./lib/index.js",
66
"author": "GraphQL Editor, Artur Czemiel",

packages/graphql-zeus/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-zeus",
3-
"version": "7.1.5",
3+
"version": "7.1.6",
44
"private": false,
55
"scripts": {
66
"start": "ttsc --watch",
@@ -27,8 +27,8 @@
2727
"config-maker": "^0.0.6",
2828
"cross-fetch": "^3.0.4",
2929
"graphql-js-tree": "^3.0.4",
30-
"graphql-zeus-core": "^7.1.5",
31-
"graphql-zeus-jsonschema": "^7.1.5",
30+
"graphql-zeus-core": "^7.1.6",
31+
"graphql-zeus-jsonschema": "^7.1.6",
3232
"yargs": "^16.1.1"
3333
}
3434
}

0 commit comments

Comments
 (0)