diff --git a/tests/benchmarks/test_execution_async.py b/tests/benchmarks/test_execution_async.py new file mode 100644 index 00000000..f2d7eb32 --- /dev/null +++ b/tests/benchmarks/test_execution_async.py @@ -0,0 +1,50 @@ +import asyncio +from graphql import ( + GraphQLSchema, + GraphQLObjectType, + GraphQLField, + GraphQLString, + graphql, +) + + +user = GraphQLObjectType( + name="User", + fields={ + "id": GraphQLField(GraphQLString), + "name": GraphQLField(GraphQLString), + }, +) + + +async def resolve_user(obj, info): + return { + "id": "1", + "name": "Sarah", + } + + +schema = GraphQLSchema( + query=GraphQLObjectType( + name="Query", + fields={ + "user": GraphQLField( + user, + resolve=resolve_user, + ) + }, + ) +) + + +def test_execute_basic_async(benchmark): + result = benchmark( + lambda: asyncio.run(graphql(schema, "query { user { id, name }}")) + ) + assert not result.errors + assert result.data == { + "user": { + "id": "1", + "name": "Sarah", + }, + } diff --git a/tests/benchmarks/test_execution_sync.py b/tests/benchmarks/test_execution_sync.py new file mode 100644 index 00000000..bfdb7cc2 --- /dev/null +++ b/tests/benchmarks/test_execution_sync.py @@ -0,0 +1,47 @@ +from graphql import ( + GraphQLSchema, + GraphQLObjectType, + GraphQLField, + GraphQLString, + graphql_sync, +) + + +user = GraphQLObjectType( + name="User", + fields={ + "id": GraphQLField(GraphQLString), + "name": GraphQLField(GraphQLString), + }, +) + + +def resolve_user(obj, info): + return { + "id": "1", + "name": "Sarah", + } + + +schema = GraphQLSchema( + query=GraphQLObjectType( + name="Query", + fields={ + "user": GraphQLField( + user, + resolve=resolve_user, + ) + }, + ) +) + + +def test_execute_basic_sync(benchmark): + result = benchmark(lambda: graphql_sync(schema, "query { user { id, name }}")) + assert not result.errors + assert result.data == { + "user": { + "id": "1", + "name": "Sarah", + }, + }