Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_fusion-runtime-605-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-mesh/fusion-runtime': patch
---

dependencies updates:

- Added dependency [`@graphql-tools/batch-execute@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/batch-execute/v/workspace:^) (to `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/chatty-humans-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-mesh/fusion-runtime': minor
---

Extract subgraph execution batching logic outside, so batching is handled by the Gateway not Stitching

**BREAKING**; `UnifiedGraphHandlerOpts` no longer takes `batch` option, it is handled by the runtime itself
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": "workspace:^",
"@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
9 changes: 9 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 { getBatchingExecutor } 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 @@ -237,6 +240,12 @@ export function getOnSubgraphExecute({
// Caches the lazy executor to prevent race conditions
subgraphExecutorMap.set(subgraphName, executor);
}
if (batch) {
executor = getBatchingExecutor(
executionRequest.context || subgraphExecutorMap,
executor,
);
}
return executor(executionRequest);
};
}
Expand Down
1 change: 1 addition & 0 deletions 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": "workspace:^"
"@graphql-tools/delegate": "workspace:^"
"@graphql-tools/executor": "npm:^1.3.10"
"@graphql-tools/federation": "workspace:^"
Expand Down
Loading