Skip to content

Commit d841932

Browse files
committed
feat(execution): add field batch resolver mode
Introduce the experimental field batch resolver execution mode behind enableBatchResolvers: 'field'. The option is typed by BatchResolverLevel, and regular field execution remains the path for fields that do not define experimentalBatchResolve. Example option: execute({ schema, document, enableBatchResolvers: 'field' }); Example field resolver: const name = { type: GraphQLString, experimentalBatchResolve: (sources) => sources.map((source) => source.name), };
1 parent b5c36e7 commit d841932

23 files changed

Lines changed: 3649 additions & 751 deletions

benchmark/batch-resolution-benchmark.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const WidgetType = new GraphQLObjectType({
1414
id: { type: GraphQLID },
1515
widget: {
1616
type: WidgetType,
17+
resolve: async (source) => {
18+
await Promise.resolve();
19+
return source.widget;
20+
},
1721
experimentalBatchResolve: async (sources) => {
1822
await Promise.resolve();
1923
return sources.map((source) => source.widget);
@@ -45,11 +49,12 @@ const rootValue = {
4549
const document = parse(`{ widgets(first: 10000) { id widget { id } } }`);
4650

4751
export const benchmark = {
48-
name: 'Execute Batch Resolved Widget Field',
52+
name: 'Execute Async Widget Field With Batch Resolver',
4953
measure: () =>
5054
execute({
5155
schema,
5256
document,
5357
rootValue,
58+
enableBatchResolvers: true,
5459
}),
5560
};

0 commit comments

Comments
 (0)