File tree 1 file changed +48
-0
lines changed
1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
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 schema = buildSchema ( 'type Query { field(echo: String!): [String] }' ) ;
6
+
7
+ const integers = Array . from ( { length : 100 } , ( _ , i ) => i + 1 ) ;
8
+
9
+ const document = parse (
10
+ `
11
+ query WithManyFragmentArguments(${ integers
12
+ . map ( ( i ) => `$echo${ i } : String` )
13
+ . join ( ', ' ) } ) {
14
+ ${ integers . map ( ( i ) => `echo${ i } : field(echo: $echo${ i } )` ) . join ( '\n' ) }
15
+ ${ integers . map ( ( i ) => `...EchoFragment${ i } (echo: $echo${ i } )` ) . join ( '\n' ) }
16
+ }
17
+
18
+ ${ integers
19
+ . map (
20
+ ( i ) =>
21
+ `fragment EchoFragment${ i } ($echo: String) on Query { echoFragment${ i } : field(echo: $echo) }` ,
22
+ )
23
+ . join ( '\n' ) }
24
+ ` ,
25
+ { experimentalFragmentArguments : true } ,
26
+ ) ;
27
+
28
+ const variableValues = Object . create ( null ) ;
29
+ for ( const i of integers ) {
30
+ variableValues [ `echo${ i } ` ] = `Echo ${ i } ` ;
31
+ }
32
+
33
+ function field ( _ , args ) {
34
+ return args . echo ;
35
+ }
36
+
37
+ export const benchmark = {
38
+ name : 'Execute Operation with Fragment Arguments' ,
39
+ count : 10 ,
40
+ async measure ( ) {
41
+ await execute ( {
42
+ schema,
43
+ document,
44
+ rootValue : { field } ,
45
+ variableValues,
46
+ } ) ;
47
+ } ,
48
+ } ;
You can’t perform that action at this time.
0 commit comments