@graphql-tools/batch-execute 10.3.0 → 10.3.1-rc-f7596fdf71c1b2144a3964ad3a79c6aeadf3d1d4
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 +7 -0
- package/dist/index.cjs +20 -4
- package/dist/index.js +20 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @graphql-tools/batch-execute
|
|
2
2
|
|
|
3
|
+
## 10.3.1-rc-f7596fdf71c1b2144a3964ad3a79c6aeadf3d1d4
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [`9877255`](https://github.com/graphql-hive/gateway/commit/98772559ea8a529b3c6235722ac5cc7b82992c11) Thanks [@enisdenjo](https://github.com/enisdenjo)! - Batch only requests that share the same `context` in `createBatchingExecutor`
|
|
9
|
+
|
|
3
10
|
## 10.3.0
|
|
4
11
|
### Minor Changes
|
|
5
12
|
|
package/dist/index.cjs
CHANGED
|
@@ -361,15 +361,31 @@ function splitResult({ data, errors }, numResults) {
|
|
|
361
361
|
|
|
362
362
|
function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer = defaultExtensionsReducer, defer = false) {
|
|
363
363
|
const loadFn = createLoadFn(executor, extensionsReducer, defer);
|
|
364
|
-
const
|
|
365
|
-
const
|
|
364
|
+
const loadersByObjectContext = /* @__PURE__ */ new WeakMap();
|
|
365
|
+
const loadersByPrimitiveContext = /* @__PURE__ */ new Map();
|
|
366
|
+
function getLoaders(context) {
|
|
367
|
+
const isObject = typeof context === "object" && context !== null || typeof context === "function";
|
|
368
|
+
let loaders = isObject ? loadersByObjectContext.get(context) : loadersByPrimitiveContext.get(context);
|
|
369
|
+
if (!loaders) {
|
|
370
|
+
loaders = {
|
|
371
|
+
query: new DataLoader__default.default(loadFn, dataLoaderOptions),
|
|
372
|
+
mutation: new DataLoader__default.default(loadFn, dataLoaderOptions)
|
|
373
|
+
};
|
|
374
|
+
if (isObject) {
|
|
375
|
+
loadersByObjectContext.set(context, loaders);
|
|
376
|
+
} else {
|
|
377
|
+
loadersByPrimitiveContext.set(context, loaders);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return loaders;
|
|
381
|
+
}
|
|
366
382
|
return function batchingExecutor(request) {
|
|
367
383
|
const operationType = request.operationType ?? utils.getOperationASTFromRequest(request)?.operation;
|
|
368
384
|
switch (operationType) {
|
|
369
385
|
case "query":
|
|
370
|
-
return
|
|
386
|
+
return getLoaders(request.context).query.load(request);
|
|
371
387
|
case "mutation":
|
|
372
|
-
return
|
|
388
|
+
return getLoaders(request.context).mutation.load(request);
|
|
373
389
|
case "subscription":
|
|
374
390
|
return executor(request);
|
|
375
391
|
default:
|
package/dist/index.js
CHANGED
|
@@ -355,15 +355,31 @@ function splitResult({ data, errors }, numResults) {
|
|
|
355
355
|
|
|
356
356
|
function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer = defaultExtensionsReducer, defer = false) {
|
|
357
357
|
const loadFn = createLoadFn(executor, extensionsReducer, defer);
|
|
358
|
-
const
|
|
359
|
-
const
|
|
358
|
+
const loadersByObjectContext = /* @__PURE__ */ new WeakMap();
|
|
359
|
+
const loadersByPrimitiveContext = /* @__PURE__ */ new Map();
|
|
360
|
+
function getLoaders(context) {
|
|
361
|
+
const isObject = typeof context === "object" && context !== null || typeof context === "function";
|
|
362
|
+
let loaders = isObject ? loadersByObjectContext.get(context) : loadersByPrimitiveContext.get(context);
|
|
363
|
+
if (!loaders) {
|
|
364
|
+
loaders = {
|
|
365
|
+
query: new DataLoader(loadFn, dataLoaderOptions),
|
|
366
|
+
mutation: new DataLoader(loadFn, dataLoaderOptions)
|
|
367
|
+
};
|
|
368
|
+
if (isObject) {
|
|
369
|
+
loadersByObjectContext.set(context, loaders);
|
|
370
|
+
} else {
|
|
371
|
+
loadersByPrimitiveContext.set(context, loaders);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return loaders;
|
|
375
|
+
}
|
|
360
376
|
return function batchingExecutor(request) {
|
|
361
377
|
const operationType = request.operationType ?? getOperationASTFromRequest(request)?.operation;
|
|
362
378
|
switch (operationType) {
|
|
363
379
|
case "query":
|
|
364
|
-
return
|
|
380
|
+
return getLoaders(request.context).query.load(request);
|
|
365
381
|
case "mutation":
|
|
366
|
-
return
|
|
382
|
+
return getLoaders(request.context).mutation.load(request);
|
|
367
383
|
case "subscription":
|
|
368
384
|
return executor(request);
|
|
369
385
|
default:
|
package/package.json
CHANGED