@vladimirdev635/gql-client 0.0.42 → 0.0.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vladimirdev635/gql-client",
3
- "version": "0.0.42",
3
+ "version": "0.0.43",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
package/parser.js CHANGED
@@ -17,14 +17,18 @@ export function createParser(parserOptions = defaultParserOptions) {
17
17
  assert(stream !== null);
18
18
  const reader = stream.getReader();
19
19
  const decoder = new TextDecoder();
20
- return async function* () {
21
- while (true) {
20
+ let shouldClose = false;
21
+ const cancel = () => shouldClose = true;
22
+ const streamGen = async function* () {
23
+ while (!shouldClose) {
22
24
  const readResult = await reader.read();
23
- if (readResult.done)
25
+ if (readResult.done || shouldClose)
24
26
  break;
25
27
  const lines = decoder.decode(readResult.value)
26
28
  .split('\n');
27
29
  for (const line of lines.filter(c => c !== '')) {
30
+ if (shouldClose)
31
+ return;
28
32
  const [name, value] = line.split(/:(.*)/s, 2);
29
33
  if (name !== 'data')
30
34
  continue;
@@ -32,6 +36,7 @@ export function createParser(parserOptions = defaultParserOptions) {
32
36
  }
33
37
  }
34
38
  }();
39
+ return { stream: streamGen, cancel };
35
40
  }
36
41
  const json = await options.response.json();
37
42
  if (json.errors) {
package/types/parser.d.ts CHANGED
@@ -6,7 +6,10 @@ export interface ClientParserParseBodyOptions<TClientContext, TRequestContext ex
6
6
  operation: TOperation;
7
7
  response: Response;
8
8
  }
9
- export type SubOpAsyncIterable<TResult> = AsyncIterable<TResult, void, unknown>;
9
+ export type SubOpAsyncIterable<TResult> = {
10
+ stream: AsyncIterable<TResult, void, unknown>;
11
+ close: () => void;
12
+ };
10
13
  export type ParseBodyFuncType<TClientContext, TRequestContext extends RequestContext> = {
11
14
  <TSyncOp extends SyncOperation>(options: ClientParserParseBodyOptions<TClientContext, TRequestContext, TSyncOp>): PromiseOrValue<OperationResult<TSyncOp>>;
12
15
  <TSubOp extends SubscriptionOperation>(options: ClientParserParseBodyOptions<TClientContext, TRequestContext, TSubOp>): PromiseOrValue<SubOpAsyncIterable<OperationResult<TSubOp>>>;