Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple execute benchmarks for both sync and async execution #141

Merged
merged 1 commit into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions tests/benchmarks/test_execution_async.py
Original file line number Diff line number Diff line change
@@ -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",
},
}
47 changes: 47 additions & 0 deletions tests/benchmarks/test_execution_sync.py
Original file line number Diff line number Diff line change
@@ -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",
},
}