From e35a3fe1a5bb8558a0b04ac21f898da583e249cd Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Thu, 23 Apr 2026 06:09:16 +0300 Subject: [PATCH] add async object field benchmark --- benchmark/object-async-benchmark.js | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 benchmark/object-async-benchmark.js diff --git a/benchmark/object-async-benchmark.js b/benchmark/object-async-benchmark.js new file mode 100644 index 0000000000..ed5e178ee9 --- /dev/null +++ b/benchmark/object-async-benchmark.js @@ -0,0 +1,32 @@ +import { execute } from 'graphql/execution/execute.js'; +import { parse } from 'graphql/language/parser.js'; +import { buildSchema } from 'graphql/utilities/buildASTSchema.js'; + +const fieldCount = 1000; +const fieldNames = Array.from( + { length: fieldCount }, + (_, index) => `f${index}`, +); + +const schema = buildSchema( + `type Query { ${fieldNames.map((fieldName) => `${fieldName}: Int`).join(' ')} }`, +); + +const document = parse(`{ ${fieldNames.join(' ')} }`); + +const rootValue = Object.fromEntries( + fieldNames.map((fieldName, index) => [ + fieldName, + () => Promise.resolve(index), + ]), +); + +export const benchmark = { + name: 'Execute Asynchronous Fields', + measure: () => + execute({ + schema, + document, + rootValue, + }), +};