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/angry-plants-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-hive/gateway-runtime': patch
---

Rename `__experimental__batchDelegation` to `__experimental__batchExecution`

Because it enables/disabled batch execution, and not delegation.
8 changes: 8 additions & 0 deletions .changeset/shaggy-trains-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@graphql-mesh/fusion-runtime': minor
'@graphql-hive/gateway-runtime': minor
---

Allow configuring some of the batch delegation options

Like the `maxBatchSize` which is used to limit the number of items requested in a single delegated batch.
1 change: 0 additions & 1 deletion internal/perf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"canvas": "^3.1.2",
"chart.js": "^4.4.7",
"chartjs-plugin-trendline": "^2.1.9",
"memlab": "^1.1.59",
"parse-duration": "^2.0.0",
"speedscope": "./speedscope-1.23.0-alpha.4.tgz",
"ws": "^8.18.3"
Expand Down
2 changes: 2 additions & 0 deletions packages/fusion-runtime/src/federation/supergraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export const handleFederationSupergraph: UnifiedGraphHandler = function ({
onDelegationPlanHooks,
onDelegationStageExecuteHooks,
onDelegateHooks,
batchDelegateOptions,
additionalTypeDefs: additionalTypeDefsFromConfig = [],
additionalResolvers: additionalResolversFromConfig = [],
logger,
Expand Down Expand Up @@ -187,6 +188,7 @@ export const handleFederationSupergraph: UnifiedGraphHandler = function ({

let executableUnifiedGraph = getStitchedSchemaFromSupergraphSdl({
supergraphSdl: getDocumentNodeFromSchema(unifiedGraph),
batchDelegateOptions,
/**
* This visits over the subgraph schema to get;
* - Extra Type Defs and Resolvers (additionalTypeDefs & additionalResolvers)
Expand Down
20 changes: 20 additions & 0 deletions packages/fusion-runtime/src/unifiedGraphManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ export function ensureSchema(source: GraphQLSchema | DocumentNode | string) {
}
return source;
}
/**
* Configure the batch delegation options for all merged types in all subschemas.
*/
export interface BatchDelegateOptions {
/**
* Limits the number of items that get requested when performing batch delegation.
* @default Infinity
*/
maxBatchSize?: number;
}

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

logger?: Logger;
}
Expand Down Expand Up @@ -104,6 +118,11 @@ export interface UnifiedGraphManagerOptions<TContext> {
* @default true
*/
batch?: boolean;
/**
* Configure the batch delegation options for all merged types in all subschemas.
*/
batchDelegateOptions?: BatchDelegateOptions;

instrumentation?: () => Instrumentation | undefined;

onUnifiedGraphChange?(newUnifiedGraph: GraphQLSchema): void;
Expand Down Expand Up @@ -309,6 +328,7 @@ export class UnifiedGraphManager<TContext> implements AsyncDisposable {
onDelegationPlanHooks: this.onDelegationPlanHooks,
onDelegationStageExecuteHooks: this.onDelegationStageExecuteHooks,
onDelegateHooks: this.opts.onDelegateHooks,
batchDelegateOptions: this.opts.batchDelegateOptions,
logger: this.opts.transportContext?.logger,
});
const transportExecutorStack = new AsyncDisposableStack();
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime/src/createGatewayRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,8 @@ export function createGatewayRuntime<
additionalTypeDefs: config.additionalTypeDefs,
additionalResolvers: config.additionalResolvers as IResolvers[],
instrumentation: () => instrumentation,
batch: config.__experimental__batchDelegation,
batch: config.__experimental__batchExecution,
batchDelegateOptions: config.__experimental__batchDelegateOptions,
});
getSchema = () => unifiedGraphManager.getUnifiedGraph();
readinessChecker = () => {
Expand Down
12 changes: 11 additions & 1 deletion packages/runtime/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Plugin as EnvelopPlugin } from '@envelop/core';
import type { useGenericAuth } from '@envelop/generic-auth';
import { HivePubSub } from '@graphql-hive/pubsub';
import type {
BatchDelegateOptions,
Instrumentation as GatewayRuntimeInstrumentation,
TransportEntryAdditions,
Transports,
Expand Down Expand Up @@ -674,7 +675,16 @@ interface GatewayConfigBase<TContext extends Record<string, any>> {
*
* @experimental
*/
__experimental__batchDelegation?: boolean;
__experimental__batchExecution?: boolean;

/**
* Configure the delegation batching options for all types on all subgraphs
*
* Do not use it unless you know what you are doing!
*
* @experimental
*/
__experimental__batchDelegateOptions?: BatchDelegateOptions;

/**
* Subgraph error handling
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/tests/sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ it.skipIf(globalThis.Bun)(
upstreamYoga.fetch,
),
],
__experimental__batchDelegation: false,
__experimental__batchExecution: false,
});
const res = gw.fetch('http://localhost:4000/graphql', {
method: 'POST',
Expand Down
Loading
Loading