Skip to content

Commit 23cfd3b

Browse files
authored
benchmark: add async object field benchmark (#4690)
1 parent 1aa5a03 commit 23cfd3b

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { execute } from 'graphql/execution/execute.js';
2+
import { parse } from 'graphql/language/parser.js';
3+
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';
4+
5+
const fieldCount = 1000;
6+
const fieldNames = Array.from(
7+
{ length: fieldCount },
8+
(_, index) => `f${index}`,
9+
);
10+
11+
const schema = buildSchema(
12+
`type Query { ${fieldNames.map((fieldName) => `${fieldName}: Int`).join(' ')} }`,
13+
);
14+
15+
const document = parse(`{ ${fieldNames.join(' ')} }`);
16+
17+
const rootValue = Object.fromEntries(
18+
fieldNames.map((fieldName, index) => [
19+
fieldName,
20+
() => Promise.resolve(index),
21+
]),
22+
);
23+
24+
export const benchmark = {
25+
name: 'Execute Asynchronous Fields',
26+
measure: () =>
27+
execute({
28+
schema,
29+
document,
30+
rootValue,
31+
}),
32+
};

0 commit comments

Comments
 (0)