@graphql-box/worker-client 5.4.3 → 5.4.5

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@graphql-box/worker-client",
3
3
  "description": "The GraphQL Box web worker client module.",
4
- "version": "5.4.3",
4
+ "version": "5.4.5",
5
5
  "author": "Dylan Aubrey",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/graphql-box",
@@ -41,18 +41,18 @@
41
41
  "iterall": "^1.3.0",
42
42
  "lodash-es": "^4.17.21",
43
43
  "uuid": "^11.0.3",
44
- "@graphql-box/core": "5.4.0",
45
- "@graphql-box/helpers": "5.4.0"
44
+ "@graphql-box/core": "5.4.1",
45
+ "@graphql-box/helpers": "5.4.1"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "graphql": "<17",
49
- "@graphql-box/client": "5.4.0"
49
+ "@graphql-box/client": "5.4.1"
50
50
  },
51
51
  "devDependencies": {
52
52
  "cts-types": "^0.0.8",
53
53
  "del-cli": "^6.0.0",
54
54
  "graphql": "^16.9.0",
55
- "@graphql-box/client": "5.4.0"
55
+ "@graphql-box/client": "5.4.1"
56
56
  },
57
57
  "keywords": [
58
58
  "client",
package/src/main.ts CHANGED
@@ -115,7 +115,7 @@ export class WorkerClient {
115
115
  errors.push(new ArgsError('@graphql-box/worker-client expected options.cache.'));
116
116
  }
117
117
 
118
- if (!('worker' in options)) {
118
+ if (!options.lazyWorkerInit && !('worker' in options)) {
119
119
  errors.push(new ArgsError('@graphql-box/worker-client expected options.worker.'));
120
120
  }
121
121
 
@@ -138,7 +138,7 @@ export class WorkerClient {
138
138
  .catch((error: unknown) => {
139
139
  throw error;
140
140
  });
141
- } else {
141
+ } else if (options.worker) {
142
142
  this._worker = options.worker;
143
143
  this._addEventListener();
144
144
  }
@@ -164,6 +164,12 @@ export class WorkerClient {
164
164
  return this._subscribe(request, options, this._getRequestContext(OperationTypeNode.SUBSCRIPTION, request));
165
165
  }
166
166
 
167
+ public set worker(worker: Worker) {
168
+ this._worker = worker;
169
+ this._addEventListener();
170
+ this._releaseMessageQueue();
171
+ }
172
+
167
173
  private _addEventListener(): void {
168
174
  if (!this._worker) {
169
175
  throw new Error('A worker is required for the WorkerClient to work correctly.');
package/src/types.ts CHANGED
@@ -21,10 +21,15 @@ export interface UserOptions {
21
21
  * of spec in 16.1.0-experimental-stream-defer.6
22
22
  */
23
23
  experimentalDeferStreamSupport?: boolean;
24
+ /**
25
+ * Must be passed in as true if you are going to
26
+ * initialise the worker after the constructor.
27
+ */
28
+ lazyWorkerInit?: boolean;
24
29
  /**
25
30
  * The web worker instance.
26
31
  */
27
- worker: Worker | (() => Worker | Promise<Worker>);
32
+ worker?: Worker | (() => Worker | Promise<Worker>);
28
33
  }
29
34
 
30
35
  export type MethodNames = 'request' | 'subscribe';