Skip to content

Commit e5eb881

Browse files
authored
Configure some batch delegation options (#1403)
1 parent 5aefad2 commit e5eb881

File tree

9 files changed

+66
-582
lines changed

9 files changed

+66
-582
lines changed

.changeset/angry-plants-hide.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@graphql-hive/gateway-runtime': patch
3+
---
4+
5+
Rename `__experimental__batchDelegation` to `__experimental__batchExecution`
6+
7+
Because it enables/disabled batch execution, and not delegation.

.changeset/shaggy-trains-camp.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@graphql-mesh/fusion-runtime': minor
3+
'@graphql-hive/gateway-runtime': minor
4+
---
5+
6+
Allow configuring some of the batch delegation options
7+
8+
Like the `maxBatchSize` which is used to limit the number of items requested in a single delegated batch.

internal/perf/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"canvas": "^3.1.2",
99
"chart.js": "^4.4.7",
1010
"chartjs-plugin-trendline": "^2.1.9",
11-
"memlab": "^1.1.59",
1211
"parse-duration": "^2.0.0",
1312
"speedscope": "./speedscope-1.23.0-alpha.4.tgz",
1413
"ws": "^8.18.3"

packages/fusion-runtime/src/federation/supergraph.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export const handleFederationSupergraph: UnifiedGraphHandler = function ({
156156
onDelegationPlanHooks,
157157
onDelegationStageExecuteHooks,
158158
onDelegateHooks,
159+
batchDelegateOptions,
159160
additionalTypeDefs: additionalTypeDefsFromConfig = [],
160161
additionalResolvers: additionalResolversFromConfig = [],
161162
logger,
@@ -187,6 +188,7 @@ export const handleFederationSupergraph: UnifiedGraphHandler = function ({
187188

188189
let executableUnifiedGraph = getStitchedSchemaFromSupergraphSdl({
189190
supergraphSdl: getDocumentNodeFromSchema(unifiedGraph),
191+
batchDelegateOptions,
190192
/**
191193
* This visits over the subgraph schema to get;
192194
* - Extra Type Defs and Resolvers (additionalTypeDefs & additionalResolvers)

packages/fusion-runtime/src/unifiedGraphManager.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ export function ensureSchema(source: GraphQLSchema | DocumentNode | string) {
5555
}
5656
return source;
5757
}
58+
/**
59+
* Configure the batch delegation options for all merged types in all subschemas.
60+
*/
61+
export interface BatchDelegateOptions {
62+
/**
63+
* Limits the number of items that get requested when performing batch delegation.
64+
* @default Infinity
65+
*/
66+
maxBatchSize?: number;
67+
}
5868

5969
export type UnifiedGraphHandler = (
6070
opts: UnifiedGraphHandlerOpts,
@@ -68,6 +78,10 @@ export interface UnifiedGraphHandlerOpts {
6878
onDelegationPlanHooks?: OnDelegationPlanHook<any>[];
6979
onDelegationStageExecuteHooks?: OnDelegationStageExecuteHook<any>[];
7080
onDelegateHooks?: OnDelegateHook<unknown>[];
81+
/**
82+
* Configure the batch delegation options for all merged types in all subschemas.
83+
*/
84+
batchDelegateOptions?: BatchDelegateOptions;
7185

7286
logger?: Logger;
7387
}
@@ -104,6 +118,11 @@ export interface UnifiedGraphManagerOptions<TContext> {
104118
* @default true
105119
*/
106120
batch?: boolean;
121+
/**
122+
* Configure the batch delegation options for all merged types in all subschemas.
123+
*/
124+
batchDelegateOptions?: BatchDelegateOptions;
125+
107126
instrumentation?: () => Instrumentation | undefined;
108127

109128
onUnifiedGraphChange?(newUnifiedGraph: GraphQLSchema): void;
@@ -309,6 +328,7 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
309328
onDelegationPlanHooks: this.onDelegationPlanHooks,
310329
onDelegationStageExecuteHooks: this.onDelegationStageExecuteHooks,
311330
onDelegateHooks: this.opts.onDelegateHooks,
331+
batchDelegateOptions: this.opts.batchDelegateOptions,
312332
logger: this.opts.transportContext?.logger,
313333
});
314334
const transportExecutorStack = new AsyncDisposableStack();

packages/runtime/src/createGatewayRuntime.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,8 @@ export function createGatewayRuntime<
728728
additionalTypeDefs: config.additionalTypeDefs,
729729
additionalResolvers: config.additionalResolvers as IResolvers[],
730730
instrumentation: () => instrumentation,
731-
batch: config.__experimental__batchDelegation,
731+
batch: config.__experimental__batchExecution,
732+
batchDelegateOptions: config.__experimental__batchDelegateOptions,
732733
});
733734
getSchema = () => unifiedGraphManager.getUnifiedGraph();
734735
readinessChecker = () => {

packages/runtime/src/types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Plugin as EnvelopPlugin } from '@envelop/core';
22
import type { useGenericAuth } from '@envelop/generic-auth';
33
import { HivePubSub } from '@graphql-hive/pubsub';
44
import type {
5+
BatchDelegateOptions,
56
Instrumentation as GatewayRuntimeInstrumentation,
67
TransportEntryAdditions,
78
Transports,
@@ -674,7 +675,16 @@ interface GatewayConfigBase<TContext extends Record<string, any>> {
674675
*
675676
* @experimental
676677
*/
677-
__experimental__batchDelegation?: boolean;
678+
__experimental__batchExecution?: boolean;
679+
680+
/**
681+
* Configure the delegation batching options for all types on all subgraphs
682+
*
683+
* Do not use it unless you know what you are doing!
684+
*
685+
* @experimental
686+
*/
687+
__experimental__batchDelegateOptions?: BatchDelegateOptions;
678688

679689
/**
680690
* Subgraph error handling

packages/runtime/tests/sync.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ it.skipIf(globalThis.Bun)(
5151
upstreamYoga.fetch,
5252
),
5353
],
54-
__experimental__batchDelegation: false,
54+
__experimental__batchExecution: false,
5555
});
5656
const res = gw.fetch('http://localhost:4000/graphql', {
5757
method: 'POST',

0 commit comments

Comments
 (0)