@graphql-tools/batch-execute
Advanced tools
Comparing version 8.0.0-alpha-85613327.0 to 8.0.0-alpha-8df6fca9.0
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,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'); | ||
@@ -68,3 +68,2 @@ | ||
var mergedExtensions = Object.create(null); | ||
var operation; | ||
for (var index in requests) { | ||
@@ -77,3 +76,2 @@ var request = requests[index]; | ||
if (isOperationDefinition(def)) { | ||
operation = def.operation; | ||
mergedSelections.push.apply(mergedSelections, tslib.__spreadArray([], tslib.__read(def.selectionSet.selections))); | ||
@@ -99,8 +97,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, | ||
@@ -120,3 +115,3 @@ selectionSet: { | ||
context: requests[0].context, | ||
info: requests[0].info, | ||
operationType: requests[0].operationType, | ||
}; | ||
@@ -145,2 +140,3 @@ } | ||
variables: prefixedVariables, | ||
operationType: request.operationType, | ||
}; | ||
@@ -310,3 +306,5 @@ } | ||
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); | ||
}; | ||
} | ||
@@ -317,4 +315,3 @@ function createLoadFn(executor, extensionsReducer) { | ||
var execBatches, index, request, currentBatch, operationType, currentOperationType, executionResults; | ||
var _a, _b; | ||
return tslib.__generator(this, function (_c) { | ||
return tslib.__generator(this, function (_a) { | ||
execBatches = []; | ||
@@ -325,8 +322,5 @@ index = 0; | ||
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.'); | ||
} | ||
operationType = request.operationType; | ||
while (++index < requests.length) { | ||
currentOperationType = (_b = graphql.getOperationAST(requests[index].document, undefined)) === null || _b === void 0 ? void 0 : _b.operation; | ||
currentOperationType = requests[index].operationType; | ||
if (operationType == null) { | ||
@@ -393,3 +387,3 @@ throw new Error('Could not identify operation type of document.'); | ||
var getBatchingExecutor = memoize2of4(function (_context, executor, dataLoaderOptions, extensionsReducer) { | ||
var getBatchingExecutor = memoize2of4(function getBatchingExecutor(_context, executor, dataLoaderOptions, extensionsReducer) { | ||
return createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer); | ||
@@ -396,0 +390,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": "8.0.0-alpha-85613327.0", | ||
"version": "8.0.0-alpha-8df6fca9.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-85613327.0", | ||
"@graphql-tools/utils": "8.0.0-alpha-8df6fca9.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>>; |
26
index.js
@@ -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'); | ||
@@ -66,3 +66,2 @@ | ||
let mergedExtensions = Object.create(null); | ||
let operation; | ||
for (const index in requests) { | ||
@@ -73,3 +72,2 @@ const request = requests[index]; | ||
if (isOperationDefinition(def)) { | ||
operation = def.operation; | ||
mergedSelections.push(...def.selectionSet.selections); | ||
@@ -87,8 +85,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, | ||
@@ -108,3 +103,3 @@ selectionSet: { | ||
context: requests[0].context, | ||
info: requests[0].info, | ||
operationType: requests[0].operationType, | ||
}; | ||
@@ -132,2 +127,3 @@ } | ||
variables: prefixedVariables, | ||
operationType: request.operationType, | ||
}; | ||
@@ -307,7 +303,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; | ||
const execBatches = []; | ||
@@ -318,8 +315,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) { | ||
@@ -383,3 +377,3 @@ throw new Error('Could not identify operation type of document.'); | ||
const getBatchingExecutor = memoize2of4(function (_context, executor, dataLoaderOptions, extensionsReducer) { | ||
const getBatchingExecutor = memoize2of4(function getBatchingExecutor(_context, executor, dataLoaderOptions, extensionsReducer) { | ||
return createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer); | ||
@@ -386,0 +380,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": "8.0.0-alpha-85613327.0", | ||
"version": "8.0.0-alpha-8df6fca9.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-85613327.0", | ||
"@graphql-tools/utils": "8.0.0-alpha-8df6fca9.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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
64149
1578
+ Added@graphql-tools/utils@8.0.0-alpha-8df6fca9.0(transitive)
- Removed@graphql-tools/utils@8.0.0-alpha-85613327.0(transitive)