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 benchmark for generic inputs #3547

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Changes from 1 commit
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
75 changes: 75 additions & 0 deletions tests/benchmarks/test_generic_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import asyncio
from typing import Generic, List, Optional, TypeVar

from pytest_codspeed.plugin import BenchmarkFixture

import strawberry

T = TypeVar("T")


@strawberry.input(description="Filter for GraphQL queries")
class GraphQLFilter(Generic[T]):
"""EXTERNAL Filter for GraphQL queries"""

eq: Optional[T] = None
in_: Optional[List[T]] = None
nin: Optional[List[T]] = None
gt: Optional[T] = None
gte: Optional[T] = None
lt: Optional[T] = None
lte: Optional[T] = None
contains: Optional[T] = None
icontains: Optional[T] = None


@strawberry.type
class Author:
name: str


@strawberry.type
class Book:
title: str

@strawberry.field
async def authors(
self,
name: GraphQLFilter[str] | None = None,
) -> List[Author]:
patrick91 marked this conversation as resolved.
Show resolved Hide resolved
return [Author(name="F. Scott Fitzgerald")]


def get_books():
return [
Book(title="The Great Gatsby"),
] * 10000


@strawberry.type
class Query:
books: List[Book] = strawberry.field(resolver=get_books)


schema = strawberry.Schema(query=Query)

query = """{
books {
title
authors(name: {eq: "F. Scott Fitzgerald"}) {
name
}
}
}
"""


def test_execute_generic_input(benchmark: BenchmarkFixture):
patrick91 marked this conversation as resolved.
Show resolved Hide resolved
def run():
coroutine = schema.execute(query)

return asyncio.run(coroutine)

result = benchmark(run)

assert not result.errors
patrick91 marked this conversation as resolved.
Show resolved Hide resolved
Loading