From 134827d26cad73844c22718f316abaf60ba34c98 Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Sat, 10 Oct 2020 20:24:49 +0300 Subject: [PATCH] fix(batching): memoize createDefaultExecutor to allow batching when using the default executor --- packages/delegate/src/delegateToSchema.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/delegate/src/delegateToSchema.ts b/packages/delegate/src/delegateToSchema.ts index 63f95bff012..031260d1a77 100644 --- a/packages/delegate/src/delegateToSchema.ts +++ b/packages/delegate/src/delegateToSchema.ts @@ -27,7 +27,6 @@ import { SubschemaConfig, ExecutionParams, StitchingInfo, - Endpoint, Transform, Executor, } from './types'; @@ -36,6 +35,7 @@ import { isSubschemaConfig } from './subschemaConfig'; import { Subschema } from './Subschema'; import { createRequestFromInfo, getDelegatingOperation } from './createRequest'; import { Transformer } from './Transformer'; +import { memoize2 } from './memoize'; export function delegateToSchema(options: IDelegateToSchemaOptions): any { const { @@ -196,6 +196,8 @@ export function delegateRequest({ }); } +const emptyObject = {}; + function collectTargetParameters( subschema: GraphQLSchema | SubschemaConfig, rootValue: Record, @@ -205,7 +207,6 @@ function collectTargetParameters( targetSchema: GraphQLSchema; targetRootValue: Record; subschemaConfig?: SubschemaConfig; - endpoint?: Endpoint; allTransforms: Array; } { const stitchingInfo: StitchingInfo = info?.schema.extensions?.stitchingInfo; @@ -215,7 +216,7 @@ function collectTargetParameters( if (isSubschemaConfig(subschemaOrSubschemaConfig)) { return { targetSchema: subschemaOrSubschemaConfig.schema, - targetRootValue: rootValue ?? subschemaOrSubschemaConfig?.rootValue ?? info?.rootValue, + targetRootValue: rootValue ?? subschemaOrSubschemaConfig?.rootValue ?? info?.rootValue ?? emptyObject, subschemaConfig: subschemaOrSubschemaConfig, endpoint: subschemaOrSubschemaConfig.endpoint ?? subschemaOrSubschemaConfig, allTransforms: @@ -227,7 +228,7 @@ function collectTargetParameters( return { targetSchema: subschemaOrSubschemaConfig, - targetRootValue: rootValue ?? info?.rootValue, + targetRootValue: rootValue ?? info?.rootValue ?? emptyObject, allTransforms: transforms, }; } @@ -244,7 +245,7 @@ function validateRequest(targetSchema: GraphQLSchema, document: DocumentNode) { } } -function createDefaultExecutor(schema: GraphQLSchema, rootValue: Record): Executor { +const createDefaultExecutor = memoize2(function (schema: GraphQLSchema, rootValue: Record): Executor { return (({ document, context, variables, info }: ExecutionParams) => execute({ schema, @@ -253,7 +254,7 @@ function createDefaultExecutor(schema: GraphQLSchema, rootValue: Record) { return ({ document, context, variables, info }: ExecutionParams) =>