@graphql-tools/batch-execute 10.2.0 → 10.3.0-rc-cf7097bc627eec19aaf61ed223cd967287a3674c
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/CHANGELOG.md +27 -0
- package/dist/index.cjs +152 -11
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +153 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @graphql-tools/batch-execute
|
|
2
2
|
|
|
3
|
+
## 10.3.0-rc-cf7097bc627eec19aaf61ed223cd967287a3674c
|
|
4
|
+
### Minor Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#2672](https://github.com/graphql-hive/gateway/pull/2672) [`befdb8e`](https://github.com/graphql-hive/gateway/commit/befdb8e3e352650c9f6c4e5fbeadfcf3615ee6ae) Thanks [@ardatan](https://github.com/ardatan)! - Support `@defer` / `@stream` incremental delivery within schema stitching.
|
|
9
|
+
|
|
10
|
+
**Gateway-owned `@defer` (default):** deferred selections are omitted from subgraph requests (only `@requires` / key dependencies are kept), so nested `@defer` can flush before slow fields resolve. Missing fields are filled later via type-merging or source resolvers.
|
|
11
|
+
|
|
12
|
+
**Subgraph-forwarded `@defer`:** set `defer: true` on a `SubschemaConfig` (or `defer: true` on `getStitchedSchemaFromSupergraphSdl`) to forward `@defer` to that subgraph and merge incremental patches via `IncrementalReceiver`. With `batch: true` and `batchingOptions.defer` (or `subschema.defer`), multi-request batches wrap each root selection in `@defer` for subgraph compatibility; results are still collected before DataLoader waiters resolve. Single-request batches pass the AsyncIterable through so the initial payload can flush before deferred patches arrive.
|
|
13
|
+
|
|
14
|
+
**Hive Gateway config:** extend `deferStream` instead of a separate flag:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
deferStream: true // client-facing only (gateway-owned omit)
|
|
18
|
+
deferStream: { subgraph: true } // also forward @defer to every subgraph
|
|
19
|
+
deferStream: { subgraph: { users: true, '*': false } } // per-subgraph
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`@graphql-tools/executor-http` adds `mergeIncremental` (default `true`: legacy growing snapshots). Set `mergeIncremental: false` to yield raw multipart parts like the default schema executor. Hive Gateway's `@graphql-mesh/transport-http` always uses passthrough (`mergeIncremental: false`).
|
|
23
|
+
|
|
24
|
+
`IncrementalReceiver` prefers raw patches and cheaply tolerates accumulated snapshots (only fills missing keys). The HTTP executor preserves `hasNext` in accumulate mode.
|
|
25
|
+
|
|
26
|
+
`@stream` continues to be forwarded on field directives as before. List streaming in `@graphql-tools/delegate` uses a plain async generator (no `@repeaterjs/repeater` dependency).
|
|
27
|
+
|
|
28
|
+
Hive Router runtime does not plan incremental delivery yet; `deferStream.subgraph` applies to the stitching federation path.
|
|
29
|
+
|
|
3
30
|
## 10.2.0
|
|
4
31
|
### Minor Changes
|
|
5
32
|
|
package/dist/index.cjs
CHANGED
|
@@ -46,7 +46,7 @@ function parseKeyFromPath(path) {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
function mergeRequests(requests, extensionsReducer) {
|
|
49
|
+
function mergeRequests(requests, extensionsReducer, defer = false) {
|
|
50
50
|
const firstRequest = requests[0];
|
|
51
51
|
if (!firstRequest) {
|
|
52
52
|
throw new Error("At least one request is required");
|
|
@@ -78,7 +78,11 @@ function mergeRequests(requests, extensionsReducer) {
|
|
|
78
78
|
const prefixedRequests = prefixRequest(createPrefix(index), request);
|
|
79
79
|
for (const def of prefixedRequests.document.definitions) {
|
|
80
80
|
if (isOperationDefinition(def)) {
|
|
81
|
-
|
|
81
|
+
const selections = defer ? wrapRootSelectionsInDefer(
|
|
82
|
+
def.selectionSet.selections,
|
|
83
|
+
`batch_${index}`
|
|
84
|
+
) : def.selectionSet.selections;
|
|
85
|
+
mergedSelections.push(...selections);
|
|
82
86
|
operationType ??= def.operation;
|
|
83
87
|
operationName ??= def.name?.value;
|
|
84
88
|
if (def.variableDefinitions) {
|
|
@@ -256,6 +260,30 @@ function isOperationDefinition(def) {
|
|
|
256
260
|
function isFragmentDefinition(def) {
|
|
257
261
|
return def.kind === graphql.Kind.FRAGMENT_DEFINITION;
|
|
258
262
|
}
|
|
263
|
+
function wrapRootSelectionsInDefer(selections, label) {
|
|
264
|
+
return [
|
|
265
|
+
{
|
|
266
|
+
kind: graphql.Kind.INLINE_FRAGMENT,
|
|
267
|
+
directives: [
|
|
268
|
+
{
|
|
269
|
+
kind: graphql.Kind.DIRECTIVE,
|
|
270
|
+
name: { kind: graphql.Kind.NAME, value: "defer" },
|
|
271
|
+
arguments: [
|
|
272
|
+
{
|
|
273
|
+
kind: graphql.Kind.ARGUMENT,
|
|
274
|
+
name: { kind: graphql.Kind.NAME, value: "label" },
|
|
275
|
+
value: { kind: graphql.Kind.STRING, value: label }
|
|
276
|
+
}
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
],
|
|
280
|
+
selectionSet: {
|
|
281
|
+
kind: graphql.Kind.SELECTION_SET,
|
|
282
|
+
selections: [...selections]
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
];
|
|
286
|
+
}
|
|
259
287
|
|
|
260
288
|
function splitResult({ data, errors }, numResults) {
|
|
261
289
|
const splitResults = new Array(numResults);
|
|
@@ -325,8 +353,8 @@ function splitResult({ data, errors }, numResults) {
|
|
|
325
353
|
return splitResults;
|
|
326
354
|
}
|
|
327
355
|
|
|
328
|
-
function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer = defaultExtensionsReducer) {
|
|
329
|
-
const loadFn = createLoadFn(executor, extensionsReducer);
|
|
356
|
+
function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer = defaultExtensionsReducer, defer = false) {
|
|
357
|
+
const loadFn = createLoadFn(executor, extensionsReducer, defer);
|
|
330
358
|
const queryLoader = new DataLoader__default.default(loadFn, dataLoaderOptions);
|
|
331
359
|
const mutationLoader = new DataLoader__default.default(loadFn, dataLoaderOptions);
|
|
332
360
|
return function batchingExecutor(request) {
|
|
@@ -343,18 +371,109 @@ function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer =
|
|
|
343
371
|
}
|
|
344
372
|
};
|
|
345
373
|
}
|
|
346
|
-
function createLoadFn(executor, extensionsReducer) {
|
|
374
|
+
function createLoadFn(executor, extensionsReducer, defer) {
|
|
347
375
|
return function batchExecuteLoadFn(requests) {
|
|
348
376
|
if (requests.length === 1 && requests[0]) {
|
|
349
377
|
const request = requests[0];
|
|
350
378
|
return promiseHelpers.fakePromise().then(() => executor(request)).catch((err) => err).then((res) => [res]);
|
|
351
379
|
}
|
|
352
|
-
const mergedRequests = mergeRequests(requests, extensionsReducer);
|
|
380
|
+
const mergedRequests = mergeRequests(requests, extensionsReducer, defer);
|
|
353
381
|
return promiseHelpers.fakePromise().then(() => executor(mergedRequests)).then(
|
|
354
|
-
(resultBatches) =>
|
|
355
|
-
|
|
382
|
+
(resultBatches) => (
|
|
383
|
+
// Batched @defer merges patches into one result per original request
|
|
384
|
+
collectExecutionResult(resultBatches)
|
|
385
|
+
)
|
|
386
|
+
).then((result) => splitResult(result, requests.length)).catch((err) => requests.map(() => err));
|
|
356
387
|
};
|
|
357
388
|
}
|
|
389
|
+
async function collectExecutionResult(result) {
|
|
390
|
+
if (!utils.isAsyncIterable(result)) {
|
|
391
|
+
return result;
|
|
392
|
+
}
|
|
393
|
+
const merged = { data: /* @__PURE__ */ Object.create(null) };
|
|
394
|
+
for await (const chunk of result) {
|
|
395
|
+
if (chunk.data) {
|
|
396
|
+
Object.assign(merged.data, chunk.data);
|
|
397
|
+
}
|
|
398
|
+
if (chunk.errors?.length) {
|
|
399
|
+
merged.errors = [...merged.errors ?? [], ...chunk.errors];
|
|
400
|
+
}
|
|
401
|
+
if (chunk.incremental) {
|
|
402
|
+
for (const patch of chunk.incremental) {
|
|
403
|
+
if (patch.errors?.length) {
|
|
404
|
+
merged.errors = [...merged.errors ?? [], ...patch.errors];
|
|
405
|
+
}
|
|
406
|
+
if (patch.items != null) {
|
|
407
|
+
if (Array.isArray(patch.path) && patch.path.length > 0) {
|
|
408
|
+
setItemsAtPath(
|
|
409
|
+
merged.data,
|
|
410
|
+
patch.path,
|
|
411
|
+
patch.items
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (patch.data == null) {
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
if (!patch.path?.length) {
|
|
420
|
+
Object.assign(merged.data, patch.data);
|
|
421
|
+
} else {
|
|
422
|
+
setAtPath(merged.data, patch.path, patch.data);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return merged;
|
|
428
|
+
}
|
|
429
|
+
function isUnsafeKey(key) {
|
|
430
|
+
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
431
|
+
}
|
|
432
|
+
function setAtPath(root, path, value) {
|
|
433
|
+
let current = root;
|
|
434
|
+
for (let i = 0; i < path.length; i++) {
|
|
435
|
+
const key = path[i];
|
|
436
|
+
if (isUnsafeKey(key)) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
if (i === path.length - 1) {
|
|
440
|
+
if (current[key] != null && typeof current[key] === "object") {
|
|
441
|
+
Object.assign(current[key], value);
|
|
442
|
+
} else {
|
|
443
|
+
current[key] = value;
|
|
444
|
+
}
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (current[key] == null || typeof current[key] !== "object") {
|
|
448
|
+
current[key] = typeof path[i + 1] === "number" ? [] : {};
|
|
449
|
+
}
|
|
450
|
+
current = current[key];
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function setItemsAtPath(root, path, items) {
|
|
454
|
+
const index = path[path.length - 1];
|
|
455
|
+
if (typeof index !== "number") {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
const listPath = path.slice(0, -1);
|
|
459
|
+
let parent = root;
|
|
460
|
+
for (let i = 0; i < listPath.length; i++) {
|
|
461
|
+
const key = listPath[i];
|
|
462
|
+
if (isUnsafeKey(key)) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
if (parent[key] == null || typeof parent[key] !== "object") {
|
|
466
|
+
parent[key] = i === listPath.length - 1 || typeof listPath[i + 1] === "number" ? [] : {};
|
|
467
|
+
}
|
|
468
|
+
parent = parent[key];
|
|
469
|
+
}
|
|
470
|
+
if (!Array.isArray(parent)) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
for (let i = 0; i < items.length; i++) {
|
|
474
|
+
parent[index + i] = items[i];
|
|
475
|
+
}
|
|
476
|
+
}
|
|
358
477
|
function defaultExtensionsReducer(mergedExtensions, request) {
|
|
359
478
|
const newExtensions = request.extensions;
|
|
360
479
|
if (newExtensions != null) {
|
|
@@ -363,9 +482,31 @@ function defaultExtensionsReducer(mergedExtensions, request) {
|
|
|
363
482
|
return mergedExtensions;
|
|
364
483
|
}
|
|
365
484
|
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
485
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
486
|
+
function getBatchingExecutor(context, executor, dataLoaderOptions, extensionsReducer, defer) {
|
|
487
|
+
let byExecutor = cache.get(context);
|
|
488
|
+
if (!byExecutor) {
|
|
489
|
+
byExecutor = /* @__PURE__ */ new WeakMap();
|
|
490
|
+
cache.set(context, byExecutor);
|
|
491
|
+
}
|
|
492
|
+
let byDefer = byExecutor.get(executor);
|
|
493
|
+
if (!byDefer) {
|
|
494
|
+
byDefer = /* @__PURE__ */ new Map();
|
|
495
|
+
byExecutor.set(executor, byDefer);
|
|
496
|
+
}
|
|
497
|
+
const deferKey = defer ? "1" : "0";
|
|
498
|
+
let batchingExecutor = byDefer.get(deferKey);
|
|
499
|
+
if (!batchingExecutor) {
|
|
500
|
+
batchingExecutor = createBatchingExecutor(
|
|
501
|
+
executor,
|
|
502
|
+
dataLoaderOptions,
|
|
503
|
+
extensionsReducer,
|
|
504
|
+
defer
|
|
505
|
+
);
|
|
506
|
+
byDefer.set(deferKey, batchingExecutor);
|
|
507
|
+
}
|
|
508
|
+
return batchingExecutor;
|
|
509
|
+
}
|
|
369
510
|
|
|
370
511
|
exports.createBatchingExecutor = createBatchingExecutor;
|
|
371
512
|
exports.getBatchingExecutor = getBatchingExecutor;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Executor, ExecutionRequest, MaybeAsyncIterable } from '@graphql-tools/utils';
|
|
2
2
|
import DataLoader from 'dataloader';
|
|
3
3
|
|
|
4
|
-
declare function createBatchingExecutor(executor: Executor, dataLoaderOptions?: DataLoader.Options<ExecutionRequest, MaybeAsyncIterable<any>>, extensionsReducer?: (mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any
|
|
4
|
+
declare function createBatchingExecutor(executor: Executor, dataLoaderOptions?: DataLoader.Options<ExecutionRequest, MaybeAsyncIterable<any>>, extensionsReducer?: (mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>, defer?: boolean): Executor;
|
|
5
5
|
|
|
6
|
-
declare
|
|
6
|
+
declare function getBatchingExecutor(context: Record<string, any>, executor: Executor, dataLoaderOptions?: DataLoader.Options<any, any, any> | undefined, extensionsReducer?: undefined | ((mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>), defer?: boolean): Executor;
|
|
7
7
|
|
|
8
8
|
export { createBatchingExecutor, getBatchingExecutor };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Executor, ExecutionRequest, MaybeAsyncIterable } from '@graphql-tools/utils';
|
|
2
2
|
import DataLoader from 'dataloader';
|
|
3
3
|
|
|
4
|
-
declare function createBatchingExecutor(executor: Executor, dataLoaderOptions?: DataLoader.Options<ExecutionRequest, MaybeAsyncIterable<any>>, extensionsReducer?: (mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any
|
|
4
|
+
declare function createBatchingExecutor(executor: Executor, dataLoaderOptions?: DataLoader.Options<ExecutionRequest, MaybeAsyncIterable<any>>, extensionsReducer?: (mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>, defer?: boolean): Executor;
|
|
5
5
|
|
|
6
|
-
declare
|
|
6
|
+
declare function getBatchingExecutor(context: Record<string, any>, executor: Executor, dataLoaderOptions?: DataLoader.Options<any, any, any> | undefined, extensionsReducer?: undefined | ((mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>), defer?: boolean): Executor;
|
|
7
7
|
|
|
8
8
|
export { createBatchingExecutor, getBatchingExecutor };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { relocatedError, getOperationASTFromRequest,
|
|
1
|
+
import { relocatedError, getOperationASTFromRequest, isAsyncIterable } from '@graphql-tools/utils';
|
|
2
2
|
import { fakePromise } from '@whatwg-node/promise-helpers';
|
|
3
3
|
import DataLoader from 'dataloader';
|
|
4
4
|
import { Kind, visit } from 'graphql';
|
|
@@ -40,7 +40,7 @@ function parseKeyFromPath(path) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
function mergeRequests(requests, extensionsReducer) {
|
|
43
|
+
function mergeRequests(requests, extensionsReducer, defer = false) {
|
|
44
44
|
const firstRequest = requests[0];
|
|
45
45
|
if (!firstRequest) {
|
|
46
46
|
throw new Error("At least one request is required");
|
|
@@ -72,7 +72,11 @@ function mergeRequests(requests, extensionsReducer) {
|
|
|
72
72
|
const prefixedRequests = prefixRequest(createPrefix(index), request);
|
|
73
73
|
for (const def of prefixedRequests.document.definitions) {
|
|
74
74
|
if (isOperationDefinition(def)) {
|
|
75
|
-
|
|
75
|
+
const selections = defer ? wrapRootSelectionsInDefer(
|
|
76
|
+
def.selectionSet.selections,
|
|
77
|
+
`batch_${index}`
|
|
78
|
+
) : def.selectionSet.selections;
|
|
79
|
+
mergedSelections.push(...selections);
|
|
76
80
|
operationType ??= def.operation;
|
|
77
81
|
operationName ??= def.name?.value;
|
|
78
82
|
if (def.variableDefinitions) {
|
|
@@ -250,6 +254,30 @@ function isOperationDefinition(def) {
|
|
|
250
254
|
function isFragmentDefinition(def) {
|
|
251
255
|
return def.kind === Kind.FRAGMENT_DEFINITION;
|
|
252
256
|
}
|
|
257
|
+
function wrapRootSelectionsInDefer(selections, label) {
|
|
258
|
+
return [
|
|
259
|
+
{
|
|
260
|
+
kind: Kind.INLINE_FRAGMENT,
|
|
261
|
+
directives: [
|
|
262
|
+
{
|
|
263
|
+
kind: Kind.DIRECTIVE,
|
|
264
|
+
name: { kind: Kind.NAME, value: "defer" },
|
|
265
|
+
arguments: [
|
|
266
|
+
{
|
|
267
|
+
kind: Kind.ARGUMENT,
|
|
268
|
+
name: { kind: Kind.NAME, value: "label" },
|
|
269
|
+
value: { kind: Kind.STRING, value: label }
|
|
270
|
+
}
|
|
271
|
+
]
|
|
272
|
+
}
|
|
273
|
+
],
|
|
274
|
+
selectionSet: {
|
|
275
|
+
kind: Kind.SELECTION_SET,
|
|
276
|
+
selections: [...selections]
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
];
|
|
280
|
+
}
|
|
253
281
|
|
|
254
282
|
function splitResult({ data, errors }, numResults) {
|
|
255
283
|
const splitResults = new Array(numResults);
|
|
@@ -319,8 +347,8 @@ function splitResult({ data, errors }, numResults) {
|
|
|
319
347
|
return splitResults;
|
|
320
348
|
}
|
|
321
349
|
|
|
322
|
-
function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer = defaultExtensionsReducer) {
|
|
323
|
-
const loadFn = createLoadFn(executor, extensionsReducer);
|
|
350
|
+
function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer = defaultExtensionsReducer, defer = false) {
|
|
351
|
+
const loadFn = createLoadFn(executor, extensionsReducer, defer);
|
|
324
352
|
const queryLoader = new DataLoader(loadFn, dataLoaderOptions);
|
|
325
353
|
const mutationLoader = new DataLoader(loadFn, dataLoaderOptions);
|
|
326
354
|
return function batchingExecutor(request) {
|
|
@@ -337,18 +365,109 @@ function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer =
|
|
|
337
365
|
}
|
|
338
366
|
};
|
|
339
367
|
}
|
|
340
|
-
function createLoadFn(executor, extensionsReducer) {
|
|
368
|
+
function createLoadFn(executor, extensionsReducer, defer) {
|
|
341
369
|
return function batchExecuteLoadFn(requests) {
|
|
342
370
|
if (requests.length === 1 && requests[0]) {
|
|
343
371
|
const request = requests[0];
|
|
344
372
|
return fakePromise().then(() => executor(request)).catch((err) => err).then((res) => [res]);
|
|
345
373
|
}
|
|
346
|
-
const mergedRequests = mergeRequests(requests, extensionsReducer);
|
|
374
|
+
const mergedRequests = mergeRequests(requests, extensionsReducer, defer);
|
|
347
375
|
return fakePromise().then(() => executor(mergedRequests)).then(
|
|
348
|
-
(resultBatches) =>
|
|
349
|
-
|
|
376
|
+
(resultBatches) => (
|
|
377
|
+
// Batched @defer merges patches into one result per original request
|
|
378
|
+
collectExecutionResult(resultBatches)
|
|
379
|
+
)
|
|
380
|
+
).then((result) => splitResult(result, requests.length)).catch((err) => requests.map(() => err));
|
|
350
381
|
};
|
|
351
382
|
}
|
|
383
|
+
async function collectExecutionResult(result) {
|
|
384
|
+
if (!isAsyncIterable(result)) {
|
|
385
|
+
return result;
|
|
386
|
+
}
|
|
387
|
+
const merged = { data: /* @__PURE__ */ Object.create(null) };
|
|
388
|
+
for await (const chunk of result) {
|
|
389
|
+
if (chunk.data) {
|
|
390
|
+
Object.assign(merged.data, chunk.data);
|
|
391
|
+
}
|
|
392
|
+
if (chunk.errors?.length) {
|
|
393
|
+
merged.errors = [...merged.errors ?? [], ...chunk.errors];
|
|
394
|
+
}
|
|
395
|
+
if (chunk.incremental) {
|
|
396
|
+
for (const patch of chunk.incremental) {
|
|
397
|
+
if (patch.errors?.length) {
|
|
398
|
+
merged.errors = [...merged.errors ?? [], ...patch.errors];
|
|
399
|
+
}
|
|
400
|
+
if (patch.items != null) {
|
|
401
|
+
if (Array.isArray(patch.path) && patch.path.length > 0) {
|
|
402
|
+
setItemsAtPath(
|
|
403
|
+
merged.data,
|
|
404
|
+
patch.path,
|
|
405
|
+
patch.items
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (patch.data == null) {
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
if (!patch.path?.length) {
|
|
414
|
+
Object.assign(merged.data, patch.data);
|
|
415
|
+
} else {
|
|
416
|
+
setAtPath(merged.data, patch.path, patch.data);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return merged;
|
|
422
|
+
}
|
|
423
|
+
function isUnsafeKey(key) {
|
|
424
|
+
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
425
|
+
}
|
|
426
|
+
function setAtPath(root, path, value) {
|
|
427
|
+
let current = root;
|
|
428
|
+
for (let i = 0; i < path.length; i++) {
|
|
429
|
+
const key = path[i];
|
|
430
|
+
if (isUnsafeKey(key)) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (i === path.length - 1) {
|
|
434
|
+
if (current[key] != null && typeof current[key] === "object") {
|
|
435
|
+
Object.assign(current[key], value);
|
|
436
|
+
} else {
|
|
437
|
+
current[key] = value;
|
|
438
|
+
}
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (current[key] == null || typeof current[key] !== "object") {
|
|
442
|
+
current[key] = typeof path[i + 1] === "number" ? [] : {};
|
|
443
|
+
}
|
|
444
|
+
current = current[key];
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
function setItemsAtPath(root, path, items) {
|
|
448
|
+
const index = path[path.length - 1];
|
|
449
|
+
if (typeof index !== "number") {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const listPath = path.slice(0, -1);
|
|
453
|
+
let parent = root;
|
|
454
|
+
for (let i = 0; i < listPath.length; i++) {
|
|
455
|
+
const key = listPath[i];
|
|
456
|
+
if (isUnsafeKey(key)) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (parent[key] == null || typeof parent[key] !== "object") {
|
|
460
|
+
parent[key] = i === listPath.length - 1 || typeof listPath[i + 1] === "number" ? [] : {};
|
|
461
|
+
}
|
|
462
|
+
parent = parent[key];
|
|
463
|
+
}
|
|
464
|
+
if (!Array.isArray(parent)) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
for (let i = 0; i < items.length; i++) {
|
|
468
|
+
parent[index + i] = items[i];
|
|
469
|
+
}
|
|
470
|
+
}
|
|
352
471
|
function defaultExtensionsReducer(mergedExtensions, request) {
|
|
353
472
|
const newExtensions = request.extensions;
|
|
354
473
|
if (newExtensions != null) {
|
|
@@ -357,8 +476,30 @@ function defaultExtensionsReducer(mergedExtensions, request) {
|
|
|
357
476
|
return mergedExtensions;
|
|
358
477
|
}
|
|
359
478
|
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
479
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
480
|
+
function getBatchingExecutor(context, executor, dataLoaderOptions, extensionsReducer, defer) {
|
|
481
|
+
let byExecutor = cache.get(context);
|
|
482
|
+
if (!byExecutor) {
|
|
483
|
+
byExecutor = /* @__PURE__ */ new WeakMap();
|
|
484
|
+
cache.set(context, byExecutor);
|
|
485
|
+
}
|
|
486
|
+
let byDefer = byExecutor.get(executor);
|
|
487
|
+
if (!byDefer) {
|
|
488
|
+
byDefer = /* @__PURE__ */ new Map();
|
|
489
|
+
byExecutor.set(executor, byDefer);
|
|
490
|
+
}
|
|
491
|
+
const deferKey = defer ? "1" : "0";
|
|
492
|
+
let batchingExecutor = byDefer.get(deferKey);
|
|
493
|
+
if (!batchingExecutor) {
|
|
494
|
+
batchingExecutor = createBatchingExecutor(
|
|
495
|
+
executor,
|
|
496
|
+
dataLoaderOptions,
|
|
497
|
+
extensionsReducer,
|
|
498
|
+
defer
|
|
499
|
+
);
|
|
500
|
+
byDefer.set(deferKey, batchingExecutor);
|
|
501
|
+
}
|
|
502
|
+
return batchingExecutor;
|
|
503
|
+
}
|
|
363
504
|
|
|
364
505
|
export { createBatchingExecutor, getBatchingExecutor };
|
package/package.json
CHANGED