Debian Codegraph @

tests/benchmarks/test_execution_sync.py

raw
1 from graphql import (
2 GraphQLSchema,
3 GraphQLObjectType,
4 GraphQLField,
5 GraphQLString,
6 graphql_sync,
7 )
8
9 user = GraphQLObjectType(
10 name="User",
11 fields={
12 "id": GraphQLField(GraphQLString),
13 "name": GraphQLField(GraphQLString),
14 },
15 )
16
17
18 def resolve_user(obj, info):
19 return {
20 "id": "1",
21 "name": "Sarah",
22 }
23
24
25 schema = GraphQLSchema(
26 query=GraphQLObjectType(
27 name="Query",
28 fields={
29 "user": GraphQLField(
30 user,
31 resolve=resolve_user,
32 )
33 },
34 )
35 )
36
37
38 def test_execute_basic_sync(benchmark):
39 result = benchmark(lambda: graphql_sync(schema, "query { user { id, name }}"))
40 assert not result.errors
41 assert result.data == {
42 "user": {
43 "id": "1",
44 "name": "Sarah",
45 },
46 }