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
809
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 7.1.3-alpha-12ccae3b.0 to 7.1.3-alpha-13dda459.0

4

createBatchingExecutor.d.ts
import DataLoader from 'dataloader';
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 { ExecutionRequest, Executor } from '@graphql-tools/utils';
export declare function createBatchingExecutor(executor: Executor, dataLoaderOptions?: DataLoader.Options<any, any, any>, extensionsReducer?: (mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>): Executor;
import DataLoader from 'dataloader';
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 { ExecutionRequest, Executor } from '@graphql-tools/utils';
export declare function createBatchingExecutor(executor: Executor, dataLoaderOptions?: DataLoader.Options<any, any, any>, extensionsReducer?: (mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>): Executor;
import DataLoader from 'dataloader';
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>>;
import { ExecutionRequest, 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: ExecutionRequest) => Record<string, any>) | undefined) => Executor<Record<string, any>, Record<string, any>>;

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

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

@@ -68,3 +67,2 @@

var mergedExtensions = Object.create(null);
var operation;
for (var index in requests) {

@@ -77,3 +75,2 @@ var request = requests[index];

if (isOperationDefinition(def)) {
operation = def.operation;
mergedSelections.push.apply(mergedSelections, tslib.__spreadArray([], tslib.__read(def.selectionSet.selections)));

@@ -99,8 +96,5 @@ if (def.variableDefinitions) {

}
if (operation == null) {
throw new Error('Could not identify operation type. Did the document only include fragment definitions?');
}
var mergedOperationDefinition = {
kind: graphql.Kind.OPERATION_DEFINITION,
operation: operation,
operation: requests[0].operationType,
variableDefinitions: mergedVariableDefinitions,

@@ -121,25 +115,39 @@ selectionSet: {

info: requests[0].info,
operationType: requests[0].operationType,
};
}
function prefixRequest(prefix, request) {
var _a;
var _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({}, request), { document: document });
var _a, e_2, _b;
var _c;
var executionVariables = (_c = request.variables) !== null && _c !== void 0 ? _c : {};
function prefixNode(node) {
return prefixNodeName(node, prefix);
}
document = graphql.visit(document, (_a = {},
_a[graphql.Kind.VARIABLE] = function (node) { return prefixNodeName(node, prefix); },
_a[graphql.Kind.FRAGMENT_DEFINITION] = function (node) { return prefixNodeName(node, prefix); },
_a[graphql.Kind.FRAGMENT_SPREAD] = function (node) { return prefixNodeName(node, prefix); },
_a));
var prefixedVariables = variableNames.reduce(function (acc, name) {
acc[prefix + name] = executionVariables[name];
return acc;
}, Object.create(null));
var prefixedDocument = aliasTopLevelFields(prefix, request.document);
var executionVariableNames = Object.keys(executionVariables);
if (executionVariableNames.length > 0) {
prefixedDocument = graphql.visit(prefixedDocument, (_a = {},
_a[graphql.Kind.VARIABLE] = prefixNode,
_a[graphql.Kind.FRAGMENT_DEFINITION] = prefixNode,
_a[graphql.Kind.FRAGMENT_SPREAD] = prefixNode,
_a));
}
var prefixedVariables = {};
try {
for (var executionVariableNames_1 = tslib.__values(executionVariableNames), executionVariableNames_1_1 = executionVariableNames_1.next(); !executionVariableNames_1_1.done; executionVariableNames_1_1 = executionVariableNames_1.next()) {
var variableName = executionVariableNames_1_1.value;
prefixedVariables[prefix + variableName] = executionVariables[variableName];
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (executionVariableNames_1_1 && !executionVariableNames_1_1.done && (_b = executionVariableNames_1.return)) _b.call(executionVariableNames_1);
}
finally { if (e_2) throw e_2.error; }
}
return {
document: document,
document: prefixedDocument,
variables: prefixedVariables,
operationType: request.operationType,
};

@@ -309,43 +317,53 @@ }

var loader = new DataLoader(createLoadFn(executor, extensionsReducer), dataLoaderOptions);
return function (request) { var _a; return ((_a = request.info) === null || _a === void 0 ? void 0 : _a.operation.operation) === 'subscription' ? executor(request) : loader.load(request); };
return function (request) {
return request.operationType === 'subscription' ? executor(request) : loader.load(request);
};
}
function createLoadFn(executor, extensionsReducer) {
var _this = this;
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;
request = requests[index];
currentBatch = [request];
execBatches.push(currentBatch);
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) {
throw new Error('Could not identify operation type of document.');
return function batchExecuteLoadFn(requests) {
return tslib.__awaiter(this, void 0, void 0, function () {
var execBatches, index, request, currentBatch, operationType, currentOperationType, results;
var _this = this;
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0:
execBatches = [];
index = 0;
request = requests[index];
currentBatch = [request];
execBatches.push(currentBatch);
operationType = request.operationType;
while (++index < requests.length) {
currentOperationType = requests[index].operationType;
if (operationType == null) {
throw new Error('Could not identify operation type of document.');
}
if (operationType === currentOperationType) {
currentBatch.push(requests[index]);
}
else {
currentBatch = [requests[index]];
execBatches.push(currentBatch);
}
}
return [4 /*yield*/, Promise.all(execBatches.map(function (execBatch) { return tslib.__awaiter(_this, void 0, void 0, function () {
var mergedRequests, resultBatches;
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0:
mergedRequests = mergeRequests(execBatch, extensionsReducer);
return [4 /*yield*/, executor(mergedRequests)];
case 1:
resultBatches = (_a.sent());
return [2 /*return*/, splitResult(resultBatches, execBatch.length)];
}
});
}); }))];
case 1:
results = _a.sent();
return [2 /*return*/, results.flat()];
}
if (operationType === currentOperationType) {
currentBatch.push(requests[index]);
}
else {
currentBatch = [requests[index]];
execBatches.push(currentBatch);
}
}
executionResults = execBatches.map(function (execBatch) {
var mergedRequests = mergeRequests(execBatch, extensionsReducer);
return new valueOrPromise.ValueOrPromise(function () { return executor(mergedRequests); });
});
return [2 /*return*/, valueOrPromise.ValueOrPromise.all(executionResults)
.then(function (resultBatches) {
return resultBatches.reduce(function (results, resultBatch, index) { return results.concat(splitResult(resultBatch, execBatches[index].length)); }, new Array());
})
.resolve()];
});
}); };
};
}

@@ -390,3 +408,3 @@ function defaultExtensionsReducer(mergedExtensions, request) {

var getBatchingExecutor = memoize2of4(function (_context, executor, dataLoaderOptions, extensionsReducer) {
var getBatchingExecutor = memoize2of4(function getBatchingExecutor(_context, executor, dataLoaderOptions, extensionsReducer) {
return createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer);

@@ -393,0 +411,0 @@ });

@@ -1,2 +0,2 @@

import { Request } from '@graphql-tools/utils';
import { ExecutionRequest } from '@graphql-tools/utils';
/**

@@ -36,2 +36,2 @@ * Merge multiple queries into a single query in such a way that query results

*/
export declare function mergeRequests(requests: Array<Request>, extensionsReducer: (mergedExtensions: Record<string, any>, request: Request) => Record<string, any>): Request;
export declare function mergeRequests(requests: Array<ExecutionRequest>, extensionsReducer: (mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>): ExecutionRequest;
{
"name": "@graphql-tools/batch-execute/es5",
"version": "7.1.3-alpha-12ccae3b.0",
"version": "7.1.3-alpha-13dda459.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-12ccae3b.0",
"@graphql-tools/utils": "8.0.0-alpha-13dda459.0",
"dataloader": "2.0.0",

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

import DataLoader from 'dataloader';
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>>;
import { ExecutionRequest, 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: ExecutionRequest) => Record<string, any>) | undefined) => Executor<Record<string, any>, Record<string, any>>;

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

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

@@ -66,3 +65,2 @@

let mergedExtensions = Object.create(null);
let operation;
for (const index in requests) {

@@ -73,3 +71,2 @@ const request = requests[index];

if (isOperationDefinition(def)) {
operation = def.operation;
mergedSelections.push(...def.selectionSet.selections);

@@ -87,8 +84,5 @@ if (def.variableDefinitions) {

}
if (operation == null) {
throw new Error('Could not identify operation type. Did the document only include fragment definitions?');
}
const mergedOperationDefinition = {
kind: graphql.Kind.OPERATION_DEFINITION,
operation,
operation: requests[0].operationType,
variableDefinitions: mergedVariableDefinitions,

@@ -109,2 +103,3 @@ selectionSet: {

info: requests[0].info,
operationType: requests[0].operationType,
};

@@ -114,20 +109,23 @@ }

var _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 { ...request, document };
function prefixNode(node) {
return prefixNodeName(node, prefix);
}
document = graphql.visit(document, {
[graphql.Kind.VARIABLE]: (node) => prefixNodeName(node, prefix),
[graphql.Kind.FRAGMENT_DEFINITION]: (node) => prefixNodeName(node, prefix),
[graphql.Kind.FRAGMENT_SPREAD]: (node) => prefixNodeName(node, prefix),
});
const prefixedVariables = variableNames.reduce((acc, name) => {
acc[prefix + name] = executionVariables[name];
return acc;
}, Object.create(null));
let prefixedDocument = aliasTopLevelFields(prefix, request.document);
const executionVariableNames = Object.keys(executionVariables);
if (executionVariableNames.length > 0) {
prefixedDocument = graphql.visit(prefixedDocument, {
[graphql.Kind.VARIABLE]: prefixNode,
[graphql.Kind.FRAGMENT_DEFINITION]: prefixNode,
[graphql.Kind.FRAGMENT_SPREAD]: prefixNode,
});
}
const prefixedVariables = {};
for (const variableName of executionVariableNames) {
prefixedVariables[prefix + variableName] = executionVariables[variableName];
}
return {
document,
document: prefixedDocument,
variables: prefixedVariables,
operationType: request.operationType,
};

@@ -307,7 +305,8 @@ }

const loader = new DataLoader(createLoadFn(executor, extensionsReducer), dataLoaderOptions);
return (request) => { var _a; return ((_a = request.info) === null || _a === void 0 ? void 0 : _a.operation.operation) === 'subscription' ? executor(request) : loader.load(request); };
return (request) => {
return request.operationType === 'subscription' ? executor(request) : loader.load(request);
};
}
function createLoadFn(executor, extensionsReducer) {
return async (requests) => {
var _a, _b;
return async function batchExecuteLoadFn(requests) {
const execBatches = [];

@@ -318,8 +317,5 @@ let index = 0;

execBatches.push(currentBatch);
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.');
}
const operationType = request.operationType;
while (++index < requests.length) {
const currentOperationType = (_b = graphql.getOperationAST(requests[index].document, undefined)) === null || _b === void 0 ? void 0 : _b.operation;
const currentOperationType = requests[index].operationType;
if (operationType == null) {

@@ -336,9 +332,8 @@ throw new Error('Could not identify operation type of document.');

}
const executionResults = execBatches.map(execBatch => {
const results = await Promise.all(execBatches.map(async (execBatch) => {
const mergedRequests = mergeRequests(execBatch, extensionsReducer);
return new valueOrPromise.ValueOrPromise(() => executor(mergedRequests));
});
return valueOrPromise.ValueOrPromise.all(executionResults)
.then(resultBatches => resultBatches.reduce((results, resultBatch, index) => results.concat(splitResult(resultBatch, execBatches[index].length)), new Array()))
.resolve();
const resultBatches = (await executor(mergedRequests));
return splitResult(resultBatches, execBatch.length);
}));
return results.flat();
};

@@ -384,3 +379,3 @@ }

const getBatchingExecutor = memoize2of4(function (_context, executor, dataLoaderOptions, extensionsReducer) {
const getBatchingExecutor = memoize2of4(function getBatchingExecutor(_context, executor, dataLoaderOptions, extensionsReducer) {
return createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer);

@@ -387,0 +382,0 @@ });

@@ -1,2 +0,2 @@

import { Request } from '@graphql-tools/utils';
import { ExecutionRequest } from '@graphql-tools/utils';
/**

@@ -36,2 +36,2 @@ * Merge multiple queries into a single query in such a way that query results

*/
export declare function mergeRequests(requests: Array<Request>, extensionsReducer: (mergedExtensions: Record<string, any>, request: Request) => Record<string, any>): Request;
export declare function mergeRequests(requests: Array<ExecutionRequest>, extensionsReducer: (mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>): ExecutionRequest;
{
"name": "@graphql-tools/batch-execute",
"version": "7.1.3-alpha-12ccae3b.0",
"version": "7.1.3-alpha-13dda459.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-12ccae3b.0",
"@graphql-tools/utils": "8.0.0-alpha-13dda459.0",
"dataloader": "2.0.0",

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

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