Skip to content

Commit 10f2698

Browse files
committed
feat(execution): experimental batch field resolution
1 parent b1bc0ae commit 10f2698

28 files changed

Lines changed: 4497 additions & 60 deletions
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { execute } from 'graphql/execution/execute.js';
2+
import { parse } from 'graphql/language/parser.js';
3+
import {
4+
GraphQLID,
5+
GraphQLInt,
6+
GraphQLList,
7+
GraphQLObjectType,
8+
GraphQLSchema,
9+
} from 'graphql/type/index.js';
10+
11+
const WidgetType = new GraphQLObjectType({
12+
name: 'Widget',
13+
fields: () => ({
14+
id: { type: GraphQLID },
15+
widget: {
16+
type: WidgetType,
17+
experimentalBatchResolve: async (sources) => {
18+
await Promise.resolve();
19+
return sources.map((source) => source.widget);
20+
},
21+
},
22+
widgets: { type: new GraphQLList(WidgetType) },
23+
}),
24+
});
25+
26+
const QueryType = new GraphQLObjectType({
27+
name: 'Query',
28+
fields: {
29+
widgets: {
30+
type: new GraphQLList(WidgetType),
31+
args: { first: { type: GraphQLInt } },
32+
resolve: (source, args) => source.widgets.slice(0, args.first),
33+
},
34+
},
35+
});
36+
37+
const schema = new GraphQLSchema({ query: QueryType });
38+
39+
const rootValue = {
40+
widgets: Array.from({ length: 10000 }, () => ({
41+
id: 'gid://owner/Widget/1',
42+
widget: { id: 'gid://owner/Widget/1' },
43+
})),
44+
};
45+
const document = parse(`{ widgets(first: 10000) { id widget { id } } }`);
46+
47+
export const benchmark = {
48+
name: 'Execute Batch Resolved Widget Field',
49+
measure: () =>
50+
execute({
51+
schema,
52+
document,
53+
rootValue,
54+
}),
55+
};

0 commit comments

Comments
 (0)