Skip to content

Commit

Permalink
enhance(runtime): move subgraph execution batching out
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Feb 6, 2025
1 parent 1a9f666 commit eea5d57
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-humans-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/fusion-runtime': patch
---

Extract subgraph execution batching logic outside, so batching is handled by the Gateway not Stitching
1 change: 1 addition & 0 deletions packages/fusion-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@graphql-mesh/transport-common": "workspace:^",
"@graphql-mesh/types": "^0.103.6",
"@graphql-mesh/utils": "^0.103.6",
"@graphql-tools/batch-execute": "^9.0.11",
"@graphql-tools/delegate": "workspace:^",
"@graphql-tools/executor": "^1.3.10",
"@graphql-tools/federation": "workspace:^",
Expand Down
2 changes: 0 additions & 2 deletions packages/fusion-runtime/src/federation/supergraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ export const handleFederationSupergraph: UnifiedGraphHandler = function ({
onDelegateHooks,
additionalTypeDefs: additionalTypeDefsFromConfig = [],
additionalResolvers: additionalResolversFromConfig = [],
batch = true,
logger,
}: UnifiedGraphHandlerOpts): UnifiedGraphHandlerResult {
const additionalTypeDefs = [...asArray(additionalTypeDefsFromConfig)];
Expand Down Expand Up @@ -204,7 +203,6 @@ export const handleFederationSupergraph: UnifiedGraphHandler = function ({
stitchingDirectivesTransformer,
onSubgraphExecute,
}),
batch,
onStitchingOptions(opts) {
subschemas = opts.subschemas;
opts.typeDefs = handleResolveToDirectives(
Expand Down
7 changes: 1 addition & 6 deletions packages/fusion-runtime/src/unifiedGraphManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ export interface UnifiedGraphHandlerOpts {
onDelegationPlanHooks?: OnDelegationPlanHook<any>[];
onDelegationStageExecuteHooks?: OnDelegationStageExecuteHook<any>[];
onDelegateHooks?: OnDelegateHook<unknown>[];
/**
* Whether to batch the subgraph executions.
* @default true
*/
batch?: boolean;

logger?: Logger;
}
Expand Down Expand Up @@ -327,7 +322,6 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
onDelegationPlanHooks: this.onDelegationPlanHooks,
onDelegationStageExecuteHooks: this.onDelegationStageExecuteHooks,
onDelegateHooks: this.opts.onDelegateHooks,
batch: this.batch,
logger: this.opts.transportContext?.logger,
});
this.unifiedGraph = newUnifiedGraph;
Expand All @@ -340,6 +334,7 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
getSubgraphSchema,
transportExecutorStack: this._transportExecutorStack,
getDisposeReason: () => this.disposeReason,
batch: this.batch,
});
this.inContextSDK = inContextSDK;
this.lastLoadTime = Date.now();
Expand Down
6 changes: 6 additions & 0 deletions packages/fusion-runtime/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
loggerForExecutionRequest,
requestIdByRequest,
} from '@graphql-mesh/utils';
import { createBatchingExecutor } from '@graphql-tools/batch-execute';
import {
DelegationPlanBuilder,
MergedTypeResolver,
Expand Down Expand Up @@ -168,6 +169,7 @@ export function getOnSubgraphExecute({
transportExecutorStack,
transports,
getDisposeReason,
batch = true,
}: {
onSubgraphExecuteHooks: OnSubgraphExecuteHook[];
transports?: Transports;
Expand All @@ -176,6 +178,7 @@ export function getOnSubgraphExecute({
getSubgraphSchema(subgraphName: string): GraphQLSchema;
transportExecutorStack: AsyncDisposableStack;
getDisposeReason?: () => GraphQLError | undefined;
batch?: boolean;
}) {
const subgraphExecutorMap = new Map<string, Executor>();
return function onSubgraphExecute(
Expand Down Expand Up @@ -219,6 +222,9 @@ export function getOnSubgraphExecute({
if (isDisposable(executor_)) {
transportExecutorStack.use(executor_);
}
if (batch) {
executor = createBatchingExecutor(executor_);
}
// Wraps the transport executor with hooks
executor = wrapExecutorWithHooks({
executor: executor_,
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3481,6 +3481,7 @@ __metadata:
"@graphql-mesh/transport-common": "workspace:^"
"@graphql-mesh/types": "npm:^0.103.6"
"@graphql-mesh/utils": "npm:^0.103.6"
"@graphql-tools/batch-execute": "npm:^9.0.11"
"@graphql-tools/delegate": "workspace:^"
"@graphql-tools/executor": "npm:^1.3.10"
"@graphql-tools/federation": "workspace:^"
Expand Down Expand Up @@ -3965,7 +3966,7 @@ __metadata:
languageName: unknown
linkType: soft

"@graphql-tools/batch-execute@workspace:^, @graphql-tools/batch-execute@workspace:packages/batch-execute":
"@graphql-tools/batch-execute@npm:^9.0.11, @graphql-tools/batch-execute@workspace:^, @graphql-tools/batch-execute@workspace:packages/batch-execute":
version: 0.0.0-use.local
resolution: "@graphql-tools/batch-execute@workspace:packages/batch-execute"
dependencies:
Expand Down

0 comments on commit eea5d57

Please sign in to comment.