File tree Expand file tree Collapse file tree 2 files changed +97
-0
lines changed Expand file tree Collapse file tree 2 files changed +97
-0
lines changed Original file line number Diff line number Diff line change 1+ import asyncio
2+ from graphql import (
3+ GraphQLSchema ,
4+ GraphQLObjectType ,
5+ GraphQLField ,
6+ GraphQLString ,
7+ graphql ,
8+ )
9+
10+
11+ user = GraphQLObjectType (
12+ name = "User" ,
13+ fields = {
14+ "id" : GraphQLField (GraphQLString ),
15+ "name" : GraphQLField (GraphQLString ),
16+ },
17+ )
18+
19+
20+ async def resolve_user (obj , info ):
21+ return {
22+ "id" : "1" ,
23+ "name" : "Sarah" ,
24+ }
25+
26+
27+ schema = GraphQLSchema (
28+ query = GraphQLObjectType (
29+ name = "Query" ,
30+ fields = {
31+ "user" : GraphQLField (
32+ user ,
33+ resolve = resolve_user ,
34+ )
35+ },
36+ )
37+ )
38+
39+
40+ def test_execute_basic_async (benchmark ):
41+ result = benchmark (
42+ lambda : asyncio .run (graphql (schema , "query { user { id, name }}" ))
43+ )
44+ assert not result .errors
45+ assert result .data == {
46+ "user" : {
47+ "id" : "1" ,
48+ "name" : "Sarah" ,
49+ },
50+ }
Original file line number Diff line number Diff line change 1+ from graphql import (
2+ GraphQLSchema ,
3+ GraphQLObjectType ,
4+ GraphQLField ,
5+ GraphQLString ,
6+ graphql_sync ,
7+ )
8+
9+
10+ user = GraphQLObjectType (
11+ name = "User" ,
12+ fields = {
13+ "id" : GraphQLField (GraphQLString ),
14+ "name" : GraphQLField (GraphQLString ),
15+ },
16+ )
17+
18+
19+ def resolve_user (obj , info ):
20+ return {
21+ "id" : "1" ,
22+ "name" : "Sarah" ,
23+ }
24+
25+
26+ schema = GraphQLSchema (
27+ query = GraphQLObjectType (
28+ name = "Query" ,
29+ fields = {
30+ "user" : GraphQLField (
31+ user ,
32+ resolve = resolve_user ,
33+ )
34+ },
35+ )
36+ )
37+
38+
39+ def test_execute_basic_sync (benchmark ):
40+ result = benchmark (lambda : graphql_sync (schema , "query { user { id, name }}" ))
41+ assert not result .errors
42+ assert result .data == {
43+ "user" : {
44+ "id" : "1" ,
45+ "name" : "Sarah" ,
46+ },
47+ }
You can’t perform that action at this time.
0 commit comments