@graphql-tools/url-loader 7.10.0 → 7.11.0-alpha-6c480b2d.0

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.
Files changed (29) hide show
  1. package/cjs/addCancelToResponseStream.js +12 -0
  2. package/cjs/defaultAsyncFetch.js +8 -0
  3. package/cjs/defaultSyncFetch.js +15 -0
  4. package/cjs/event-stream/handleEventStreamResponse.js +18 -0
  5. package/cjs/event-stream/handleReadable.js +31 -0
  6. package/cjs/event-stream/handleReadableStream.js +131 -0
  7. package/cjs/handleMultipartMixedResponse.js +52 -0
  8. package/{index.js → cjs/index.js} +81 -358
  9. package/cjs/package.json +1 -0
  10. package/cjs/utils.js +28 -0
  11. package/esm/addCancelToResponseStream.js +8 -0
  12. package/esm/defaultAsyncFetch.js +4 -0
  13. package/esm/defaultSyncFetch.js +10 -0
  14. package/esm/event-stream/handleEventStreamResponse.js +14 -0
  15. package/esm/event-stream/handleReadable.js +27 -0
  16. package/esm/event-stream/handleReadableStream.js +127 -0
  17. package/esm/handleMultipartMixedResponse.js +48 -0
  18. package/{index.mjs → esm/index.js} +12 -270
  19. package/esm/utils.js +22 -0
  20. package/package.json +35 -14
  21. package/{addCancelToResponseStream.d.ts → typings/addCancelToResponseStream.d.ts} +0 -0
  22. package/{defaultAsyncFetch.d.ts → typings/defaultAsyncFetch.d.ts} +0 -0
  23. package/{defaultSyncFetch.d.ts → typings/defaultSyncFetch.d.ts} +0 -0
  24. package/{event-stream → typings/event-stream}/handleEventStreamResponse.d.ts +0 -0
  25. package/{event-stream → typings/event-stream}/handleReadable.d.ts +0 -0
  26. package/{event-stream → typings/event-stream}/handleReadableStream.d.ts +0 -0
  27. package/{handleMultipartMixedResponse.d.ts → typings/handleMultipartMixedResponse.d.ts} +0 -0
  28. package/{index.d.ts → typings/index.d.ts} +2 -2
  29. /package/{utils.d.ts → typings/utils.d.ts} +0 -0
@@ -1,303 +1,27 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) { return e; } else {
9
- var n = {};
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () {
16
- return e[k];
17
- }
18
- });
19
- });
20
- }
21
- n['default'] = e;
22
- return n;
23
- }
24
- }
25
-
26
- const graphql = require('graphql');
27
- const utils = require('@graphql-tools/utils');
28
- const wrap = require('@graphql-tools/wrap');
29
- const graphqlWs = require('graphql-ws');
30
- const WebSocket = _interopDefault(require('isomorphic-ws'));
31
- const extractFiles = require('extract-files');
32
- const valueOrPromise = require('value-or-promise');
33
- const graphqlLiveQuery = require('@n1ru4l/graphql-live-query');
34
- const crossUndiciFetch = require('cross-undici-fetch');
35
- const syncFetchImported = _interopDefault(require('sync-fetch'));
36
- const node = require('meros/node');
37
- const browser = require('meros/browser');
38
- const merge = require('dset/merge');
39
-
40
- const defaultAsyncFetch = async (input, init) => {
41
- return crossUndiciFetch.fetch(input, init);
42
- };
43
-
44
- const defaultSyncFetch = (input, init) => {
45
- if (typeof input === 'string') {
46
- init === null || init === void 0 ? true : delete init.signal;
47
- }
48
- else {
49
- delete input.signal;
50
- }
51
- return syncFetchImported(input, init);
52
- };
53
-
54
- function isIncomingMessage(body) {
55
- return body != null && typeof body === 'object' && 'pipe' in body;
56
- }
57
- async function handleMultipartMixedResponse(response) {
58
- const body = await response.body;
59
- const contentType = response.headers.get('content-type') || '';
60
- let asyncIterator;
61
- if (isIncomingMessage(body)) {
62
- // Meros/node expects headers as an object map with the content-type prop
63
- body.headers = {
64
- 'content-type': contentType,
65
- };
66
- // And it expects `IncomingMessage` and `node-fetch` returns `body` as `Promise<PassThrough>`
67
- asyncIterator = (await node.meros(body));
68
- }
69
- else {
70
- // Nothing is needed for regular `Response`.
71
- asyncIterator = (await browser.meros(response));
72
- }
73
- const executionResult = {};
74
- return utils.mapAsyncIterator(asyncIterator, (part) => {
75
- if (part.json) {
76
- const chunk = part.body;
77
- if (chunk.path) {
78
- if (chunk.data) {
79
- const path = ['data'];
80
- merge.dset(executionResult, path.concat(chunk.path), chunk.data);
81
- }
82
- if (chunk.errors) {
83
- executionResult.errors = (executionResult.errors || []).concat(chunk.errors);
84
- }
85
- }
86
- else {
87
- if (chunk.data) {
88
- executionResult.data = chunk.data;
89
- }
90
- if (chunk.errors) {
91
- executionResult.errors = chunk.errors;
92
- }
93
- }
94
- return executionResult;
95
- }
96
- });
97
- }
98
-
99
- /* eslint-disable no-labels */
100
- let decodeUint8Array;
101
- if (globalThis.Buffer) {
102
- decodeUint8Array = uint8Array => globalThis.Buffer.from(uint8Array).toString('utf-8');
103
- }
104
- else {
105
- const textDecoder = new TextDecoder();
106
- decodeUint8Array = uint8Array => textDecoder.decode(uint8Array);
107
- }
108
- async function* handleReadable(readable) {
109
- outer: for await (const chunk of readable) {
110
- const chunkStr = typeof chunk === 'string' ? chunk : decodeUint8Array(chunk);
111
- for (const part of chunkStr.split('\n\n')) {
112
- if (part) {
113
- const eventStr = part.split('event: ')[1];
114
- const dataStr = part.split('data: ')[1];
115
- if (eventStr === 'complete') {
116
- break outer;
117
- }
118
- if (dataStr) {
119
- const data = JSON.parse(dataStr);
120
- yield data.payload || data;
121
- }
122
- }
123
- }
124
- }
125
- }
126
-
127
- // Based on https://github.com/Azure/fetch-event-source/blob/main/src/parse.ts
128
- async function* handleReadableStream(stream) {
129
- const decoder = new TextDecoder();
130
- const reader = stream.getReader();
131
- let buffer;
132
- let position = 0; // current read position
133
- let fieldLength = -1; // length of the `field` portion of the line
134
- let discardTrailingNewline = false;
135
- try {
136
- let result;
137
- let message = {
138
- data: '',
139
- event: '',
140
- id: '',
141
- retry: undefined,
142
- };
143
- while (!(result = await reader.read()).done) {
144
- const arr = result.value;
145
- if (buffer === undefined) {
146
- buffer = arr;
147
- position = 0;
148
- fieldLength = -1;
149
- }
150
- else {
151
- // we're still parsing the old line. Append the new bytes into buffer:
152
- buffer = concat(buffer, arr);
153
- }
154
- const bufLength = buffer.length;
155
- let lineStart = 0; // index where the current line starts
156
- while (position < bufLength) {
157
- if (discardTrailingNewline) {
158
- if (buffer[position] === 10 /* ControlChars.NewLine */) {
159
- lineStart = ++position; // skip to next char
160
- }
161
- discardTrailingNewline = false;
162
- }
163
- // start looking forward till the end of line:
164
- let lineEnd = -1; // index of the \r or \n char
165
- for (; position < bufLength && lineEnd === -1; ++position) {
166
- switch (buffer[position]) {
167
- case 58 /* ControlChars.Colon */: {
168
- if (fieldLength === -1) {
169
- // first colon in line
170
- fieldLength = position - lineStart;
171
- }
172
- break;
173
- }
174
- case 13 /* ControlChars.CarriageReturn */: {
175
- discardTrailingNewline = true;
176
- break;
177
- }
178
- case 10 /* ControlChars.NewLine */: {
179
- lineEnd = position;
180
- break;
181
- }
182
- }
183
- }
184
- if (lineEnd === -1) {
185
- // We reached the end of the buffer but the line hasn't ended.
186
- // Wait for the next arr and then continue parsing:
187
- break;
188
- }
189
- // we've reached the line end, send it out:
190
- const line = buffer.subarray(lineStart, lineEnd);
191
- if (line.length === 0) {
192
- // empty line denotes end of message. Trigger the callback and start a new message:
193
- if (message.event || message.data) {
194
- // NOT a server ping (":\n\n")
195
- yield JSON.parse(message.data);
196
- message = {
197
- data: '',
198
- event: '',
199
- id: '',
200
- retry: undefined,
201
- };
202
- }
203
- }
204
- else if (fieldLength > 0) {
205
- // exclude comments and lines with no values
206
- // line is of format "<field>:<value>" or "<field>: <value>"
207
- // https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation
208
- const field = decoder.decode(line.subarray(0, fieldLength));
209
- const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* ControlChars.Space */ ? 2 : 1);
210
- const value = decoder.decode(line.subarray(valueOffset));
211
- switch (field) {
212
- case 'data':
213
- // if this message already has data, append the new value to the old.
214
- // otherwise, just set to the new value:
215
- message.data = message.data ? message.data + '\n' + value : value; // otherwise,
216
- break;
217
- case 'event':
218
- message.event = value;
219
- break;
220
- case 'id':
221
- message.id = value;
222
- break;
223
- case 'retry': {
224
- const retry = parseInt(value, 10);
225
- message.retry = retry;
226
- break;
227
- }
228
- }
229
- }
230
- lineStart = position; // we're now on the next line
231
- fieldLength = -1;
232
- }
233
- if (lineStart === bufLength) {
234
- buffer = undefined; // we've finished reading it
235
- }
236
- else if (lineStart !== 0) {
237
- // Create a new view into buffer beginning at lineStart so we don't
238
- // need to copy over the previous lines when we get the new arr:
239
- buffer = buffer.subarray(lineStart);
240
- position -= lineStart;
241
- }
242
- }
243
- }
244
- finally {
245
- reader.releaseLock();
246
- }
247
- }
248
- function concat(a, b) {
249
- const res = new Uint8Array(a.length + b.length);
250
- res.set(a);
251
- res.set(b, a.length);
252
- return res;
253
- }
254
-
255
- async function handleEventStreamResponse(response) {
256
- // node-fetch returns body as a promise so we need to resolve it
257
- const body = await response.body;
258
- if (body) {
259
- if (utils.isAsyncIterable(body)) {
260
- return handleReadable(body);
261
- }
262
- return handleReadableStream(body);
263
- }
264
- throw new Error('Response body is expected to be a readable stream but got; ' + utils.inspect(body));
265
- }
266
-
267
- function addCancelToResponseStream(resultStream, controller) {
268
- return utils.withCancel(resultStream, () => {
269
- if (!controller.signal.aborted) {
270
- controller.abort();
271
- }
272
- });
273
- }
274
-
275
- function isBlob(obj) {
276
- return typeof obj.arrayBuffer === 'function';
277
- }
278
- function isGraphQLUpload(upload) {
279
- return typeof upload.createReadStream === 'function';
280
- }
281
- function isPromiseLike(obj) {
282
- return typeof obj.then === 'function';
283
- }
284
- var LEGACY_WS;
285
- (function (LEGACY_WS) {
286
- LEGACY_WS["CONNECTION_INIT"] = "connection_init";
287
- LEGACY_WS["CONNECTION_ACK"] = "connection_ack";
288
- LEGACY_WS["CONNECTION_ERROR"] = "connection_error";
289
- LEGACY_WS["CONNECTION_KEEP_ALIVE"] = "ka";
290
- LEGACY_WS["START"] = "start";
291
- LEGACY_WS["STOP"] = "stop";
292
- LEGACY_WS["CONNECTION_TERMINATE"] = "connection_terminate";
293
- LEGACY_WS["DATA"] = "data";
294
- LEGACY_WS["ERROR"] = "error";
295
- LEGACY_WS["COMPLETE"] = "complete";
296
- })(LEGACY_WS || (LEGACY_WS = {}));
297
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UrlLoader = exports.SubscriptionProtocol = void 0;
4
+ const tslib_1 = require("tslib");
298
5
  /* eslint-disable no-case-declarations */
299
- const asyncImport = (moduleName) => new Promise(function (resolve) { resolve(_interopNamespace(require(moduleName))); });
6
+ /// <reference lib="dom" />
7
+ const graphql_1 = require("graphql");
8
+ const utils_1 = require("@graphql-tools/utils");
9
+ const wrap_1 = require("@graphql-tools/wrap");
10
+ const graphql_ws_1 = require("graphql-ws");
11
+ const isomorphic_ws_1 = tslib_1.__importDefault(require("isomorphic-ws"));
12
+ const extract_files_1 = require("extract-files");
13
+ const value_or_promise_1 = require("value-or-promise");
14
+ const graphql_live_query_1 = require("@n1ru4l/graphql-live-query");
15
+ const defaultAsyncFetch_js_1 = require("./defaultAsyncFetch.js");
16
+ const defaultSyncFetch_js_1 = require("./defaultSyncFetch.js");
17
+ const handleMultipartMixedResponse_js_1 = require("./handleMultipartMixedResponse.js");
18
+ const handleEventStreamResponse_js_1 = require("./event-stream/handleEventStreamResponse.js");
19
+ const addCancelToResponseStream_js_1 = require("./addCancelToResponseStream.js");
20
+ const cross_undici_fetch_1 = require("cross-undici-fetch");
21
+ const utils_js_1 = require("./utils.js");
22
+ const asyncImport = (moduleName) => Promise.resolve().then(() => tslib_1.__importStar(require(moduleName)));
300
23
  const syncImport = (moduleName) => require(moduleName);
24
+ var SubscriptionProtocol;
301
25
  (function (SubscriptionProtocol) {
302
26
  SubscriptionProtocol["WS"] = "WS";
303
27
  /**
@@ -312,7 +36,7 @@ const syncImport = (moduleName) => require(moduleName);
312
36
  * Use `graphql-sse` for subscriptions
313
37
  */
314
38
  SubscriptionProtocol["GRAPHQL_SSE"] = "GRAPHQL_SSE";
315
- })(exports.SubscriptionProtocol || (exports.SubscriptionProtocol = {}));
39
+ })(SubscriptionProtocol = exports.SubscriptionProtocol || (exports.SubscriptionProtocol = {}));
316
40
  function isCompatibleUri(uri) {
317
41
  try {
318
42
  // eslint-disable-next-line no-new
@@ -338,9 +62,9 @@ function isCompatibleUri(uri) {
338
62
  class UrlLoader {
339
63
  createFormDataFromVariables({ query, variables, operationName, extensions, }) {
340
64
  const vars = Object.assign({}, variables);
341
- const { clone, files } = extractFiles.extractFiles(vars, 'variables', ((v) => extractFiles.isExtractableFile(v) ||
65
+ const { clone, files } = (0, extract_files_1.extractFiles)(vars, 'variables', ((v) => (0, extract_files_1.isExtractableFile)(v) ||
342
66
  (v === null || v === void 0 ? void 0 : v.promise) ||
343
- utils.isAsyncIterable(v) ||
67
+ (0, utils_1.isAsyncIterable)(v) ||
344
68
  (v === null || v === void 0 ? void 0 : v.then) ||
345
69
  typeof (v === null || v === void 0 ? void 0 : v.arrayBuffer) === 'function'));
346
70
  const map = {};
@@ -351,7 +75,7 @@ class UrlLoader {
351
75
  uploads[currIndex] = file;
352
76
  currIndex++;
353
77
  }
354
- const form = new crossUndiciFetch.FormData();
78
+ const form = new cross_undici_fetch_1.FormData();
355
79
  form.append('operations', JSON.stringify({
356
80
  query,
357
81
  variables: clone,
@@ -363,16 +87,16 @@ class UrlLoader {
363
87
  const indexStr = i.toString();
364
88
  if (upload != null) {
365
89
  const filename = upload.filename || upload.name || upload.path || `blob-${indexStr}`;
366
- if (isPromiseLike(upload)) {
90
+ if ((0, utils_js_1.isPromiseLike)(upload)) {
367
91
  return upload.then((resolvedUpload) => handleUpload(resolvedUpload, i));
368
92
  // If Blob
369
93
  }
370
- else if (isBlob(upload)) {
94
+ else if ((0, utils_js_1.isBlob)(upload)) {
371
95
  return upload.arrayBuffer().then((arrayBuffer) => {
372
- form.append(indexStr, new crossUndiciFetch.File([arrayBuffer], filename, { type: upload.type }), filename);
96
+ form.append(indexStr, new cross_undici_fetch_1.File([arrayBuffer], filename, { type: upload.type }), filename);
373
97
  });
374
98
  }
375
- else if (isGraphQLUpload(upload)) {
99
+ else if ((0, utils_js_1.isGraphQLUpload)(upload)) {
376
100
  const stream = upload.createReadStream();
377
101
  const chunks = [];
378
102
  return Promise.resolve().then(async () => {
@@ -382,15 +106,15 @@ class UrlLoader {
382
106
  }
383
107
  }
384
108
  const blobPart = new Uint8Array(chunks);
385
- form.append(indexStr, new crossUndiciFetch.File([blobPart], filename, { type: upload.mimetype }), filename);
109
+ form.append(indexStr, new cross_undici_fetch_1.File([blobPart], filename, { type: upload.mimetype }), filename);
386
110
  });
387
111
  }
388
112
  else {
389
- form.append(indexStr, new crossUndiciFetch.File([upload], filename), filename);
113
+ form.append(indexStr, new cross_undici_fetch_1.File([upload], filename), filename);
390
114
  }
391
115
  }
392
116
  }
393
- return valueOrPromise.ValueOrPromise.all(uploads.map((upload, i) => new valueOrPromise.ValueOrPromise(() => handleUpload(upload, i))))
117
+ return value_or_promise_1.ValueOrPromise.all(uploads.map((upload, i) => new value_or_promise_1.ValueOrPromise(() => handleUpload(upload, i))))
394
118
  .then(() => form)
395
119
  .resolve();
396
120
  }
@@ -427,21 +151,21 @@ class UrlLoader {
427
151
  });
428
152
  const executor = (request) => {
429
153
  var _a, _b;
430
- const controller = new crossUndiciFetch.AbortController();
154
+ const controller = new cross_undici_fetch_1.AbortController();
431
155
  let method = defaultMethod;
432
- const operationAst = utils.getOperationASTFromRequest(request);
156
+ const operationAst = (0, utils_1.getOperationASTFromRequest)(request);
433
157
  const operationType = operationAst.operation;
434
158
  if ((options === null || options === void 0 ? void 0 : options.useGETForQueries) && operationType === 'query') {
435
159
  method = 'GET';
436
160
  }
437
161
  let accept = 'application/json, multipart/mixed';
438
- if (operationType === 'subscription' || graphqlLiveQuery.isLiveQueryOperationDefinitionNode(operationAst)) {
162
+ if (operationType === 'subscription' || (0, graphql_live_query_1.isLiveQueryOperationDefinitionNode)(operationAst)) {
439
163
  method = 'GET';
440
164
  accept = 'text/event-stream';
441
165
  }
442
166
  const endpoint = ((_a = request.extensions) === null || _a === void 0 ? void 0 : _a.endpoint) || HTTP_URL;
443
167
  const headers = Object.assign({}, options === null || options === void 0 ? void 0 : options.headers, ((_b = request.extensions) === null || _b === void 0 ? void 0 : _b.headers) || {});
444
- const query = graphql.print(request.document);
168
+ const query = (0, graphql_1.print)(request.document);
445
169
  const requestBody = {
446
170
  query,
447
171
  variables: request.variables,
@@ -457,7 +181,7 @@ class UrlLoader {
457
181
  }, options.timeout);
458
182
  }
459
183
  const credentials = (options === null || options === void 0 ? void 0 : options.credentials) || 'same-origin';
460
- return new valueOrPromise.ValueOrPromise(() => {
184
+ return new value_or_promise_1.ValueOrPromise(() => {
461
185
  switch (method) {
462
186
  case 'GET':
463
187
  const finalUrl = this.prepareGETUrl({
@@ -475,7 +199,7 @@ class UrlLoader {
475
199
  });
476
200
  case 'POST':
477
201
  if (options === null || options === void 0 ? void 0 : options.multipart) {
478
- return new valueOrPromise.ValueOrPromise(() => this.createFormDataFromVariables(requestBody))
202
+ return new value_or_promise_1.ValueOrPromise(() => this.createFormDataFromVariables(requestBody))
479
203
  .then(form => fetch(endpoint, {
480
204
  method: 'POST',
481
205
  credentials,
@@ -513,10 +237,10 @@ class UrlLoader {
513
237
  }
514
238
  const contentType = fetchResult.headers.get('content-type');
515
239
  if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('text/event-stream')) {
516
- return handleEventStreamResponse(fetchResult).then(resultStream => addCancelToResponseStream(resultStream, controller));
240
+ return (0, handleEventStreamResponse_js_1.handleEventStreamResponse)(fetchResult).then(resultStream => (0, addCancelToResponseStream_js_1.addCancelToResponseStream)(resultStream, controller));
517
241
  }
518
242
  else if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('multipart/mixed')) {
519
- return handleMultipartMixedResponse(fetchResult).then(resultStream => addCancelToResponseStream(resultStream, controller));
243
+ return (0, handleMultipartMixedResponse_js_1.handleMultipartMixedResponse)(fetchResult).then(resultStream => (0, addCancelToResponseStream_js_1.addCancelToResponseStream)(resultStream, controller));
520
244
  }
521
245
  return fetchResult.text();
522
246
  })
@@ -548,7 +272,7 @@ class UrlLoader {
548
272
  }
549
273
  throw new Error('No result');
550
274
  }
551
- return new valueOrPromise.ValueOrPromise(() => executor(request))
275
+ return new value_or_promise_1.ValueOrPromise(() => executor(request))
552
276
  .then(res => {
553
277
  var _a;
554
278
  result = res;
@@ -573,15 +297,15 @@ class UrlLoader {
573
297
  https: 'wss',
574
298
  http: 'ws',
575
299
  });
576
- const subscriptionClient = graphqlWs.createClient({
300
+ const subscriptionClient = (0, graphql_ws_1.createClient)({
577
301
  url: WS_URL,
578
302
  webSocketImpl,
579
303
  connectionParams,
580
304
  lazy: true,
581
305
  });
582
306
  return ({ document, variables, operationName, extensions }) => {
583
- const query = graphql.print(document);
584
- return utils.observableToAsyncIterable({
307
+ const query = (0, graphql_1.print)(document);
308
+ return (0, utils_1.observableToAsyncIterable)({
585
309
  subscribe: observer => {
586
310
  const unsubscribe = subscriptionClient.subscribe({
587
311
  query,
@@ -621,7 +345,7 @@ class UrlLoader {
621
345
  break;
622
346
  }
623
347
  websocket.send(JSON.stringify({
624
- type: LEGACY_WS.CONNECTION_INIT,
348
+ type: utils_js_1.LEGACY_WS.CONNECTION_INIT,
625
349
  payload,
626
350
  }));
627
351
  };
@@ -629,7 +353,7 @@ class UrlLoader {
629
353
  const cleanupWebsocket = () => {
630
354
  if (websocket != null && observerById.size === 0) {
631
355
  websocket.send(JSON.stringify({
632
- type: LEGACY_WS.CONNECTION_TERMINATE,
356
+ type: utils_js_1.LEGACY_WS.CONNECTION_TERMINATE,
633
357
  }));
634
358
  websocket.terminate();
635
359
  websocket = null;
@@ -637,7 +361,7 @@ class UrlLoader {
637
361
  };
638
362
  return function legacyExecutor(request) {
639
363
  const id = Date.now().toString();
640
- return utils.observableToAsyncIterable({
364
+ return (0, utils_1.observableToAsyncIterable)({
641
365
  subscribe(observer) {
642
366
  ensureWebsocket();
643
367
  if (websocket == null) {
@@ -646,38 +370,38 @@ class UrlLoader {
646
370
  websocket.onmessage = event => {
647
371
  const data = JSON.parse(event.data.toString('utf-8'));
648
372
  switch (data.type) {
649
- case LEGACY_WS.CONNECTION_ACK: {
373
+ case utils_js_1.LEGACY_WS.CONNECTION_ACK: {
650
374
  if (websocket == null) {
651
375
  throw new Error(`WebSocket connection is not found!`);
652
376
  }
653
377
  websocket.send(JSON.stringify({
654
- type: LEGACY_WS.START,
378
+ type: utils_js_1.LEGACY_WS.START,
655
379
  id,
656
380
  payload: {
657
- query: graphql.print(request.document),
381
+ query: (0, graphql_1.print)(request.document),
658
382
  variables: request.variables,
659
383
  operationName: request.operationName,
660
384
  },
661
385
  }));
662
386
  break;
663
387
  }
664
- case LEGACY_WS.CONNECTION_ERROR: {
388
+ case utils_js_1.LEGACY_WS.CONNECTION_ERROR: {
665
389
  observer.error(data.payload);
666
390
  break;
667
391
  }
668
- case LEGACY_WS.CONNECTION_KEEP_ALIVE: {
392
+ case utils_js_1.LEGACY_WS.CONNECTION_KEEP_ALIVE: {
669
393
  break;
670
394
  }
671
- case LEGACY_WS.DATA: {
395
+ case utils_js_1.LEGACY_WS.DATA: {
672
396
  observer.next(data.payload);
673
397
  break;
674
398
  }
675
- case LEGACY_WS.COMPLETE: {
399
+ case utils_js_1.LEGACY_WS.COMPLETE: {
676
400
  if (websocket == null) {
677
401
  throw new Error(`WebSocket connection is not found!`);
678
402
  }
679
403
  websocket.send(JSON.stringify({
680
- type: LEGACY_WS.CONNECTION_TERMINATE,
404
+ type: utils_js_1.LEGACY_WS.CONNECTION_TERMINATE,
681
405
  }));
682
406
  observer.complete();
683
407
  cleanupWebsocket();
@@ -688,7 +412,7 @@ class UrlLoader {
688
412
  return {
689
413
  unsubscribe: () => {
690
414
  websocket === null || websocket === void 0 ? void 0 : websocket.send(JSON.stringify({
691
- type: LEGACY_WS.STOP,
415
+ type: utils_js_1.LEGACY_WS.STOP,
692
416
  id,
693
417
  }));
694
418
  cleanupWebsocket();
@@ -702,7 +426,7 @@ class UrlLoader {
702
426
  if (customFetch) {
703
427
  if (typeof customFetch === 'string') {
704
428
  const [moduleName, fetchFnName] = customFetch.split('#');
705
- return new valueOrPromise.ValueOrPromise(() => importFn(moduleName))
429
+ return new value_or_promise_1.ValueOrPromise(() => importFn(moduleName))
706
430
  .then(module => (fetchFnName ? module[fetchFnName] : module))
707
431
  .resolve();
708
432
  }
@@ -711,10 +435,10 @@ class UrlLoader {
711
435
  }
712
436
  }
713
437
  if (importFn === asyncImport) {
714
- return defaultAsyncFetch;
438
+ return defaultAsyncFetch_js_1.defaultAsyncFetch;
715
439
  }
716
440
  else {
717
- return defaultSyncFetch;
441
+ return defaultSyncFetch_js_1.defaultSyncFetch;
718
442
  }
719
443
  }
720
444
  getDefaultMethodFromOptions(method, defaultMethod) {
@@ -726,20 +450,20 @@ class UrlLoader {
726
450
  getWebSocketImpl(importFn, options) {
727
451
  if (typeof (options === null || options === void 0 ? void 0 : options.webSocketImpl) === 'string') {
728
452
  const [moduleName, webSocketImplName] = options.webSocketImpl.split('#');
729
- return new valueOrPromise.ValueOrPromise(() => importFn(moduleName))
453
+ return new value_or_promise_1.ValueOrPromise(() => importFn(moduleName))
730
454
  .then(importedModule => (webSocketImplName ? importedModule[webSocketImplName] : importedModule))
731
455
  .resolve();
732
456
  }
733
457
  else {
734
- const websocketImpl = (options === null || options === void 0 ? void 0 : options.webSocketImpl) || WebSocket;
458
+ const websocketImpl = (options === null || options === void 0 ? void 0 : options.webSocketImpl) || isomorphic_ws_1.default;
735
459
  return websocketImpl;
736
460
  }
737
461
  }
738
462
  buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options) {
739
- if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.SSE) {
463
+ if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.SSE) {
740
464
  return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, options);
741
465
  }
742
- else if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.GRAPHQL_SSE) {
466
+ else if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.GRAPHQL_SSE) {
743
467
  if (!(options === null || options === void 0 ? void 0 : options.subscriptionsEndpoint)) {
744
468
  // when no custom subscriptions endpoint is specified,
745
469
  // graphql-sse is recommended to be used on `/graphql/stream`
@@ -748,9 +472,9 @@ class UrlLoader {
748
472
  return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, options);
749
473
  }
750
474
  else {
751
- const webSocketImpl$ = new valueOrPromise.ValueOrPromise(() => this.getWebSocketImpl(importFn, options));
475
+ const webSocketImpl$ = new value_or_promise_1.ValueOrPromise(() => this.getWebSocketImpl(importFn, options));
752
476
  const executor$ = webSocketImpl$.then(webSocketImpl => {
753
- if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.LEGACY_WS) {
477
+ if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.LEGACY_WS) {
754
478
  return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, options);
755
479
  }
756
480
  else {
@@ -761,20 +485,20 @@ class UrlLoader {
761
485
  }
762
486
  }
763
487
  getExecutor(endpoint, importFn, options) {
764
- const fetch$ = new valueOrPromise.ValueOrPromise(() => this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, importFn));
488
+ const fetch$ = new value_or_promise_1.ValueOrPromise(() => this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, importFn));
765
489
  const httpExecutor$ = fetch$.then(fetch => {
766
490
  return this.buildHTTPExecutor(endpoint, fetch, options);
767
491
  });
768
- if ((options === null || options === void 0 ? void 0 : options.subscriptionsEndpoint) != null || (options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) !== exports.SubscriptionProtocol.SSE) {
492
+ if ((options === null || options === void 0 ? void 0 : options.subscriptionsEndpoint) != null || (options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) !== SubscriptionProtocol.SSE) {
769
493
  const subscriptionExecutor$ = fetch$.then(fetch => {
770
494
  const subscriptionsEndpoint = (options === null || options === void 0 ? void 0 : options.subscriptionsEndpoint) || endpoint;
771
495
  return this.buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options);
772
496
  });
773
497
  // eslint-disable-next-line no-inner-declarations
774
498
  function getExecutorByRequest(request) {
775
- const operationAst = utils.getOperationASTFromRequest(request);
499
+ const operationAst = (0, utils_1.getOperationASTFromRequest)(request);
776
500
  if (operationAst.operation === 'subscription' ||
777
- graphqlLiveQuery.isLiveQueryOperationDefinitionNode(operationAst, request.variables)) {
501
+ (0, graphql_live_query_1.isLiveQueryOperationDefinitionNode)(operationAst, request.variables)) {
778
502
  return subscriptionExecutor$;
779
503
  }
780
504
  else {
@@ -797,12 +521,12 @@ class UrlLoader {
797
521
  }
798
522
  handleSDL(pointer, fetch, options) {
799
523
  const defaultMethod = this.getDefaultMethodFromOptions(options === null || options === void 0 ? void 0 : options.method, 'GET');
800
- return new valueOrPromise.ValueOrPromise(() => fetch(pointer, {
524
+ return new value_or_promise_1.ValueOrPromise(() => fetch(pointer, {
801
525
  method: defaultMethod,
802
526
  headers: options.headers,
803
527
  }))
804
528
  .then(response => response.text())
805
- .then(schemaString => utils.parseGraphQLSDL(pointer, schemaString, options))
529
+ .then(schemaString => (0, utils_1.parseGraphQLSDL)(pointer, schemaString, options))
806
530
  .resolve();
807
531
  }
808
532
  async load(pointer, options) {
@@ -822,14 +546,14 @@ class UrlLoader {
822
546
  source.schema =
823
547
  source.schema ||
824
548
  (source.document
825
- ? graphql.buildASTSchema(source.document, options)
549
+ ? (0, graphql_1.buildASTSchema)(source.document, options)
826
550
  : source.rawSDL
827
- ? graphql.buildSchema(source.rawSDL, options)
551
+ ? (0, graphql_1.buildSchema)(source.rawSDL, options)
828
552
  : undefined);
829
553
  }
830
554
  else {
831
555
  executor = this.getExecutorAsync(pointer, options);
832
- source.schema = await wrap.introspectSchema(executor, {}, options);
556
+ source.schema = await (0, wrap_1.introspectSchema)(executor, {}, options);
833
557
  }
834
558
  if (!source.schema) {
835
559
  throw new Error(`Invalid introspected schema`);
@@ -838,7 +562,7 @@ class UrlLoader {
838
562
  executor = this.getExecutorAsync(options.endpoint, options);
839
563
  }
840
564
  if (executor) {
841
- source.schema = wrap.wrapSchema({
565
+ source.schema = (0, wrap_1.wrapSchema)({
842
566
  schema: source.schema,
843
567
  executor,
844
568
  batch: options === null || options === void 0 ? void 0 : options.batch,
@@ -863,14 +587,14 @@ class UrlLoader {
863
587
  source.schema =
864
588
  source.schema ||
865
589
  (source.document
866
- ? graphql.buildASTSchema(source.document, options)
590
+ ? (0, graphql_1.buildASTSchema)(source.document, options)
867
591
  : source.rawSDL
868
- ? graphql.buildSchema(source.rawSDL, options)
592
+ ? (0, graphql_1.buildSchema)(source.rawSDL, options)
869
593
  : undefined);
870
594
  }
871
595
  else {
872
596
  executor = this.getExecutorSync(pointer, options);
873
- source.schema = wrap.introspectSchema(executor, {}, options);
597
+ source.schema = (0, wrap_1.introspectSchema)(executor, {}, options);
874
598
  }
875
599
  if (!source.schema) {
876
600
  throw new Error(`Invalid introspected schema`);
@@ -879,7 +603,7 @@ class UrlLoader {
879
603
  executor = this.getExecutorSync(options.endpoint, options);
880
604
  }
881
605
  if (executor) {
882
- source.schema = wrap.wrapSchema({
606
+ source.schema = (0, wrap_1.wrapSchema)({
883
607
  schema: source.schema,
884
608
  executor,
885
609
  });
@@ -887,8 +611,7 @@ class UrlLoader {
887
611
  return [source];
888
612
  }
889
613
  }
614
+ exports.UrlLoader = UrlLoader;
890
615
  function switchProtocols(pointer, protocolMap) {
891
616
  return Object.entries(protocolMap).reduce((prev, [source, target]) => prev.replace(`${source}://`, `${target}://`).replace(`${source}:\\`, `${target}:\\`), pointer);
892
617
  }
893
-
894
- exports.UrlLoader = UrlLoader;