@@ -27,7 +27,6 @@ import {
2727 SubschemaConfig ,
2828 ExecutionParams ,
2929 StitchingInfo ,
30- Endpoint ,
3130 Transform ,
3231 Executor ,
3332} from './types' ;
@@ -36,6 +35,7 @@ import { isSubschemaConfig } from './subschemaConfig';
3635import { Subschema } from './Subschema' ;
3736import { createRequestFromInfo , getDelegatingOperation } from './createRequest' ;
3837import { Transformer } from './Transformer' ;
38+ import { memoize2 } from './memoize' ;
3939
4040export function delegateToSchema ( options : IDelegateToSchemaOptions ) : any {
4141 const {
@@ -196,6 +196,8 @@ export function delegateRequest({
196196 } ) ;
197197}
198198
199+ const emptyObject = { } ;
200+
199201function collectTargetParameters (
200202 subschema : GraphQLSchema | SubschemaConfig ,
201203 rootValue : Record < string , any > ,
@@ -205,7 +207,6 @@ function collectTargetParameters(
205207 targetSchema : GraphQLSchema ;
206208 targetRootValue : Record < string , any > ;
207209 subschemaConfig ?: SubschemaConfig ;
208- endpoint ?: Endpoint ;
209210 allTransforms : Array < Transform > ;
210211} {
211212 const stitchingInfo : StitchingInfo = info ?. schema . extensions ?. stitchingInfo ;
@@ -215,7 +216,7 @@ function collectTargetParameters(
215216 if ( isSubschemaConfig ( subschemaOrSubschemaConfig ) ) {
216217 return {
217218 targetSchema : subschemaOrSubschemaConfig . schema ,
218- targetRootValue : rootValue ?? subschemaOrSubschemaConfig ?. rootValue ?? info ?. rootValue ,
219+ targetRootValue : rootValue ?? subschemaOrSubschemaConfig ?. rootValue ?? info ?. rootValue ?? emptyObject ,
219220 subschemaConfig : subschemaOrSubschemaConfig ,
220221 endpoint : subschemaOrSubschemaConfig . endpoint ?? subschemaOrSubschemaConfig ,
221222 allTransforms :
@@ -227,7 +228,7 @@ function collectTargetParameters(
227228
228229 return {
229230 targetSchema : subschemaOrSubschemaConfig ,
230- targetRootValue : rootValue ?? info ?. rootValue ,
231+ targetRootValue : rootValue ?? info ?. rootValue ?? emptyObject ,
231232 allTransforms : transforms ,
232233 } ;
233234}
@@ -244,7 +245,7 @@ function validateRequest(targetSchema: GraphQLSchema, document: DocumentNode) {
244245 }
245246}
246247
247- function createDefaultExecutor ( schema : GraphQLSchema , rootValue : Record < string , any > ) : Executor {
248+ const createDefaultExecutor = memoize2 ( function ( schema : GraphQLSchema , rootValue : Record < string , any > ) : Executor {
248249 return ( ( { document, context, variables, info } : ExecutionParams ) =>
249250 execute ( {
250251 schema,
@@ -253,7 +254,7 @@ function createDefaultExecutor(schema: GraphQLSchema, rootValue: Record<string,
253254 variableValues : variables ,
254255 rootValue : rootValue ?? info ?. rootValue ,
255256 } ) ) as Executor ;
256- }
257+ } ) ;
257258
258259function createDefaultSubscriber ( schema : GraphQLSchema , rootValue : Record < string , any > ) {
259260 return ( { document, context, variables, info } : ExecutionParams ) =>
0 commit comments