Skip to content

Commit d49dddb

Browse files
committed
Add benchmark for executing fields with arguments
1 parent 894141f commit d49dddb

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from graphql import (
2+
GraphQLArgument,
3+
GraphQLField,
4+
GraphQLInt,
5+
GraphQLList,
6+
GraphQLNonNull,
7+
GraphQLObjectType,
8+
GraphQLSchema,
9+
execute_sync,
10+
parse,
11+
)
12+
13+
item = GraphQLObjectType(
14+
name="Item",
15+
fields={
16+
"value": GraphQLField(
17+
GraphQLNonNull(GraphQLInt),
18+
args={"multiplier": GraphQLArgument(GraphQLNonNull(GraphQLInt))},
19+
resolve=lambda obj, _info, multiplier: obj * multiplier,
20+
),
21+
},
22+
)
23+
24+
schema = GraphQLSchema(
25+
query=GraphQLObjectType(
26+
name="Query",
27+
fields={
28+
"items": GraphQLField(
29+
GraphQLNonNull(GraphQLList(GraphQLNonNull(item))),
30+
args={"count": GraphQLArgument(GraphQLNonNull(GraphQLInt))},
31+
resolve=lambda _obj, _info, count: range(count),
32+
)
33+
},
34+
)
35+
)
36+
37+
document = parse(
38+
"query ($count: Int!) { items(count: $count) { value(multiplier: 2) } }"
39+
)
40+
41+
42+
def test_execute_field_arguments_sync(benchmark):
43+
result = benchmark(
44+
lambda: execute_sync(schema, document, variable_values={"count": 1000})
45+
)
46+
assert not result.errors
47+
assert result.data == {"items": [{"value": i * 2} for i in range(1000)]}

0 commit comments

Comments
 (0)