New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-tools/batch-execute

Package Overview
Dependencies
Maintainers
3
Versions
706
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/batch-execute - npm Package Compare versions

Comparing version 8.0.0-alpha-e6d4bac0.0 to 8.0.0-alpha-ecfe6a6e.0

es5/mergeRequests.d.ts

4

createBatchingExecutor.d.ts
import DataLoader from 'dataloader';
import { ExecutionParams, Executor } from '@graphql-tools/utils';
export declare function createBatchingExecutor(executor: Executor, dataLoaderOptions?: DataLoader.Options<any, any, any>, extensionsReducer?: (mergedExtensions: Record<string, any>, executionParams: ExecutionParams) => Record<string, any>): Executor;
import { Request, Executor } from '@graphql-tools/utils';
export declare function createBatchingExecutor(executor: Executor, dataLoaderOptions?: DataLoader.Options<any, any, any>, extensionsReducer?: (mergedExtensions: Record<string, any>, request: Request) => Record<string, any>): Executor;
import DataLoader from 'dataloader';
import { ExecutionParams, Executor } from '@graphql-tools/utils';
export declare function createBatchingExecutor(executor: Executor, dataLoaderOptions?: DataLoader.Options<any, any, any>, extensionsReducer?: (mergedExtensions: Record<string, any>, executionParams: ExecutionParams) => Record<string, any>): Executor;
import { Request, Executor } from '@graphql-tools/utils';
export declare function createBatchingExecutor(executor: Executor, dataLoaderOptions?: DataLoader.Options<any, any, any>, extensionsReducer?: (mergedExtensions: Record<string, any>, request: Request) => Record<string, any>): Executor;
import DataLoader from 'dataloader';
import { ExecutionParams, Executor } from '@graphql-tools/utils';
export declare const getBatchingExecutor: (A1: Record<string, any>, A2: Executor<Record<string, any>, Record<string, any>>, A3: DataLoader.Options<any, any, any> | undefined, A4: ((mergedExtensions: Record<string, any>, executionParams: ExecutionParams) => Record<string, any>) | undefined) => Executor<Record<string, any>, Record<string, any>>;
import { Request, Executor } from '@graphql-tools/utils';
export declare const getBatchingExecutor: (A1: Record<string, any>, A2: Executor<Record<string, any>, Record<string, any>>, A3: DataLoader.Options<any, any, any> | undefined, A4: ((mergedExtensions: Record<string, any>, request: Request) => Record<string, any>) | undefined) => Executor<Record<string, any>, Record<string, any>>;

@@ -8,5 +8,5 @@ 'use strict';

const tslib = require('tslib');
const graphql = require('graphql');
const DataLoader = _interopDefault(require('dataloader'));
const valueOrPromise = require('value-or-promise');
const graphql = require('graphql');
const utils = require('@graphql-tools/utils/es5');

@@ -23,3 +23,3 @@

}
return null;
throw new Error("Key " + prefixedKey + " is not correctly prefixed");
}

@@ -62,3 +62,3 @@

*/
function mergeExecutionParams(execs, extensionsReducer) {
function mergeRequests(requests, extensionsReducer) {
var e_1, _a;

@@ -71,7 +71,7 @@ var mergedVariables = Object.create(null);

var operation;
for (var index in execs) {
var executionParams = execs[index];
var prefixedExecutionParams = prefixExecutionParams(createPrefix(index), executionParams);
for (var index in requests) {
var request = requests[index];
var prefixedRequests = prefixRequest(createPrefix(index), request);
try {
for (var _b = (e_1 = void 0, tslib.__values(prefixedExecutionParams.document.definitions)), _c = _b.next(); !_c.done; _c = _b.next()) {
for (var _b = (e_1 = void 0, tslib.__values(prefixedRequests.document.definitions)), _c = _b.next(); !_c.done; _c = _b.next()) {
var def = _c.value;

@@ -97,4 +97,4 @@ if (isOperationDefinition(def)) {

}
Object.assign(mergedVariables, prefixedExecutionParams.variables);
mergedExtensions = extensionsReducer(mergedExtensions, executionParams);
Object.assign(mergedVariables, prefixedRequests.variables);
mergedExtensions = extensionsReducer(mergedExtensions, request);
}

@@ -120,14 +120,14 @@ if (operation == null) {

extensions: mergedExtensions,
context: execs[0].context,
operationType: operation,
context: requests[0].context,
info: requests[0].info,
};
}
function prefixExecutionParams(prefix, executionParams) {
function prefixRequest(prefix, request) {
var _a;
var _b;
var document = aliasTopLevelFields(prefix, executionParams.document);
var executionVariables = (_b = executionParams.variables) !== null && _b !== void 0 ? _b : {};
var document = aliasTopLevelFields(prefix, request.document);
var executionVariables = (_b = request.variables) !== null && _b !== void 0 ? _b : {};
var variableNames = Object.keys(executionVariables);
if (variableNames.length === 0) {
return tslib.__assign(tslib.__assign({}, executionParams), { document: document });
return tslib.__assign(tslib.__assign({}, request), { document: document });
}

@@ -146,3 +146,2 @@ document = graphql.visit(document, (_a = {},

variables: prefixedVariables,
operationType: executionParams.operationType,
};

@@ -272,5 +271,3 @@ }

for (var prefixedKey in data) {
var parsedKey = parseKey(prefixedKey);
utils.assertSome(parsedKey, "'parsedKey' should not be null.");
var index = parsedKey.index, originalKey = parsedKey.originalKey;
var _d = parseKey(prefixedKey), index = _d.index, originalKey = _d.originalKey;
var result = splitResults[index];

@@ -294,8 +291,6 @@ if (result == null) {

var parsedKey = parseKey(error.path[0]);
if (parsedKey) {
var index = parsedKey.index, originalKey = parsedKey.originalKey;
var newError = utils.relocatedError(error, tslib.__spreadArray([originalKey], tslib.__read(error.path.slice(1))));
var errors_2 = (splitResults[index].errors = (splitResults[index].errors || []));
errors_2.push(newError);
}
var index = parsedKey.index, originalKey = parsedKey.originalKey;
var newError = utils.relocatedError(error, tslib.__spreadArray([originalKey], tslib.__read(error.path.slice(1))));
var errors_2 = (splitResults[index].errors = (splitResults[index].errors || []));
errors_2.push(newError);
}

@@ -318,19 +313,21 @@ }

var loader = new DataLoader(createLoadFn(executor, extensionsReducer), dataLoaderOptions);
return function (executionParams) {
return executionParams.operationType === 'subscription' ? executor(executionParams) : loader.load(executionParams);
};
return function (request) { var _a; return ((_a = request.info) === null || _a === void 0 ? void 0 : _a.operation.operation) === 'subscription' ? executor(request) : loader.load(request); };
}
function createLoadFn(executor, extensionsReducer) {
var _this = this;
return function (execs) { return tslib.__awaiter(_this, void 0, void 0, function () {
var execBatches, index, exec, currentBatch, operationType, currentOperationType, executionResults;
return tslib.__generator(this, function (_a) {
return function (requests) { return tslib.__awaiter(_this, void 0, void 0, function () {
var execBatches, index, request, currentBatch, operationType, currentOperationType, executionResults;
var _a, _b;
return tslib.__generator(this, function (_c) {
execBatches = [];
index = 0;
exec = execs[index];
currentBatch = [exec];
request = requests[index];
currentBatch = [request];
execBatches.push(currentBatch);
operationType = exec.operationType;
while (++index < execs.length) {
currentOperationType = execs[index].operationType;
operationType = (_a = graphql.getOperationAST(request.document, undefined)) === null || _a === void 0 ? void 0 : _a.operation;
if (operationType == null) {
throw new Error('Could not identify operation type of document.');
}
while (++index < requests.length) {
currentOperationType = (_b = graphql.getOperationAST(requests[index].document, undefined)) === null || _b === void 0 ? void 0 : _b.operation;
if (operationType == null) {

@@ -340,6 +337,6 @@ throw new Error('Could not identify operation type of document.');

if (operationType === currentOperationType) {
currentBatch.push(execs[index]);
currentBatch.push(requests[index]);
}
else {
currentBatch = [execs[index]];
currentBatch = [requests[index]];
execBatches.push(currentBatch);

@@ -349,4 +346,4 @@ }

executionResults = execBatches.map(function (execBatch) {
var mergedExecutionParams = mergeExecutionParams(execBatch, extensionsReducer);
return new valueOrPromise.ValueOrPromise(function () { return executor(mergedExecutionParams); });
var mergedRequests = mergeRequests(execBatch, extensionsReducer);
return new valueOrPromise.ValueOrPromise(function () { return executor(mergedRequests); });
});

@@ -361,4 +358,4 @@ return [2 /*return*/, valueOrPromise.ValueOrPromise.all(executionResults)

}
function defaultExtensionsReducer(mergedExtensions, executionParams) {
var newExtensions = executionParams.extensions;
function defaultExtensionsReducer(mergedExtensions, request) {
var newExtensions = request.extensions;
if (newExtensions != null) {

@@ -365,0 +362,0 @@ Object.assign(mergedExtensions, newExtensions);

{
"name": "@graphql-tools/batch-execute/es5",
"version": "8.0.0-alpha-e6d4bac0.0",
"version": "8.0.0-alpha-ecfe6a6e.0",
"description": "A set of utils for faster development of GraphQL tools",

@@ -10,3 +10,3 @@ "sideEffects": false,

"dependencies": {
"@graphql-tools/utils": "8.0.0-alpha-e6d4bac0.0",
"@graphql-tools/utils": "8.0.0-alpha-ecfe6a6e.0",
"dataloader": "2.0.0",

@@ -13,0 +13,0 @@ "tslib": "~2.3.0",

export declare function createPrefix(index: string): string;
export declare function parseKey(prefixedKey: string): null | {
export declare function parseKey(prefixedKey: string): {
index: number;
originalKey: string;
};
import DataLoader from 'dataloader';
import { ExecutionParams, Executor } from '@graphql-tools/utils';
export declare const getBatchingExecutor: (A1: Record<string, any>, A2: Executor<Record<string, any>, Record<string, any>>, A3: DataLoader.Options<any, any, any> | undefined, A4: ((mergedExtensions: Record<string, any>, executionParams: ExecutionParams) => Record<string, any>) | undefined) => Executor<Record<string, any>, Record<string, any>>;
import { Request, Executor } from '@graphql-tools/utils';
export declare const getBatchingExecutor: (A1: Record<string, any>, A2: Executor<Record<string, any>, Record<string, any>>, A3: DataLoader.Options<any, any, any> | undefined, A4: ((mergedExtensions: Record<string, any>, request: Request) => Record<string, any>) | undefined) => Executor<Record<string, any>, Record<string, any>>;

@@ -7,5 +7,5 @@ 'use strict';

const graphql = require('graphql');
const DataLoader = _interopDefault(require('dataloader'));
const valueOrPromise = require('value-or-promise');
const graphql = require('graphql');
const utils = require('@graphql-tools/utils');

@@ -22,3 +22,3 @@

}
return null;
throw new Error(`Key ${prefixedKey} is not correctly prefixed`);
}

@@ -61,3 +61,3 @@

*/
function mergeExecutionParams(execs, extensionsReducer) {
function mergeRequests(requests, extensionsReducer) {
const mergedVariables = Object.create(null);

@@ -69,6 +69,6 @@ const mergedVariableDefinitions = [];

let operation;
for (const index in execs) {
const executionParams = execs[index];
const prefixedExecutionParams = prefixExecutionParams(createPrefix(index), executionParams);
for (const def of prefixedExecutionParams.document.definitions) {
for (const index in requests) {
const request = requests[index];
const prefixedRequests = prefixRequest(createPrefix(index), request);
for (const def of prefixedRequests.document.definitions) {
if (isOperationDefinition(def)) {

@@ -85,4 +85,4 @@ operation = def.operation;

}
Object.assign(mergedVariables, prefixedExecutionParams.variables);
mergedExtensions = extensionsReducer(mergedExtensions, executionParams);
Object.assign(mergedVariables, prefixedRequests.variables);
mergedExtensions = extensionsReducer(mergedExtensions, request);
}

@@ -108,13 +108,13 @@ if (operation == null) {

extensions: mergedExtensions,
context: execs[0].context,
operationType: operation,
context: requests[0].context,
info: requests[0].info,
};
}
function prefixExecutionParams(prefix, executionParams) {
function prefixRequest(prefix, request) {
var _a;
let document = aliasTopLevelFields(prefix, executionParams.document);
const executionVariables = (_a = executionParams.variables) !== null && _a !== void 0 ? _a : {};
let document = aliasTopLevelFields(prefix, request.document);
const executionVariables = (_a = request.variables) !== null && _a !== void 0 ? _a : {};
const variableNames = Object.keys(executionVariables);
if (variableNames.length === 0) {
return { ...executionParams, document };
return { ...request, document };
}

@@ -133,3 +133,2 @@ document = graphql.visit(document, {

variables: prefixedVariables,
operationType: executionParams.operationType,
};

@@ -280,5 +279,3 @@ }

for (const prefixedKey in data) {
const parsedKey = parseKey(prefixedKey);
utils.assertSome(parsedKey, "'parsedKey' should not be null.");
const { index, originalKey } = parsedKey;
const { index, originalKey } = parseKey(prefixedKey);
const result = splitResults[index];

@@ -300,8 +297,6 @@ if (result == null) {

const parsedKey = parseKey(error.path[0]);
if (parsedKey) {
const { index, originalKey } = parsedKey;
const newError = utils.relocatedError(error, [originalKey, ...error.path.slice(1)]);
const errors = (splitResults[index].errors = (splitResults[index].errors || []));
errors.push(newError);
}
const { index, originalKey } = parsedKey;
const newError = utils.relocatedError(error, [originalKey, ...error.path.slice(1)]);
const errors = (splitResults[index].errors = (splitResults[index].errors || []));
errors.push(newError);
}

@@ -315,16 +310,18 @@ }

const loader = new DataLoader(createLoadFn(executor, extensionsReducer), dataLoaderOptions);
return (executionParams) => {
return executionParams.operationType === 'subscription' ? executor(executionParams) : loader.load(executionParams);
};
return (request) => { var _a; return ((_a = request.info) === null || _a === void 0 ? void 0 : _a.operation.operation) === 'subscription' ? executor(request) : loader.load(request); };
}
function createLoadFn(executor, extensionsReducer) {
return async (execs) => {
return async (requests) => {
var _a, _b;
const execBatches = [];
let index = 0;
const exec = execs[index];
let currentBatch = [exec];
const request = requests[index];
let currentBatch = [request];
execBatches.push(currentBatch);
const operationType = exec.operationType;
while (++index < execs.length) {
const currentOperationType = execs[index].operationType;
const operationType = (_a = graphql.getOperationAST(request.document, undefined)) === null || _a === void 0 ? void 0 : _a.operation;
if (operationType == null) {
throw new Error('Could not identify operation type of document.');
}
while (++index < requests.length) {
const currentOperationType = (_b = graphql.getOperationAST(requests[index].document, undefined)) === null || _b === void 0 ? void 0 : _b.operation;
if (operationType == null) {

@@ -334,6 +331,6 @@ throw new Error('Could not identify operation type of document.');

if (operationType === currentOperationType) {
currentBatch.push(execs[index]);
currentBatch.push(requests[index]);
}
else {
currentBatch = [execs[index]];
currentBatch = [requests[index]];
execBatches.push(currentBatch);

@@ -343,4 +340,4 @@ }

const executionResults = execBatches.map(execBatch => {
const mergedExecutionParams = mergeExecutionParams(execBatch, extensionsReducer);
return new valueOrPromise.ValueOrPromise(() => executor(mergedExecutionParams));
const mergedRequests = mergeRequests(execBatch, extensionsReducer);
return new valueOrPromise.ValueOrPromise(() => executor(mergedRequests));
});

@@ -352,4 +349,4 @@ return valueOrPromise.ValueOrPromise.all(executionResults)

}
function defaultExtensionsReducer(mergedExtensions, executionParams) {
const newExtensions = executionParams.extensions;
function defaultExtensionsReducer(mergedExtensions, request) {
const newExtensions = request.extensions;
if (newExtensions != null) {

@@ -356,0 +353,0 @@ Object.assign(mergedExtensions, newExtensions);

{
"name": "@graphql-tools/batch-execute",
"version": "8.0.0-alpha-e6d4bac0.0",
"version": "8.0.0-alpha-ecfe6a6e.0",
"description": "A set of utils for faster development of GraphQL tools",

@@ -10,3 +10,3 @@ "sideEffects": false,

"dependencies": {
"@graphql-tools/utils": "8.0.0-alpha-e6d4bac0.0",
"@graphql-tools/utils": "8.0.0-alpha-ecfe6a6e.0",
"dataloader": "2.0.0",

@@ -13,0 +13,0 @@ "tslib": "~2.3.0",

export declare function createPrefix(index: string): string;
export declare function parseKey(prefixedKey: string): null | {
export declare function parseKey(prefixedKey: string): {
index: number;
originalKey: string;
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc