Skip to content

Commit

Permalink
Add benchmark for generic inputs (#3547)
Browse files Browse the repository at this point in the history
* Add benchmark

* Bump cache?

* Fix typing issue

* Make test smaller
  • Loading branch information
patrick91 authored Jun 24, 2024
1 parent 4f67d7e commit 095463d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
.nox
key:
${{ runner.os }}-nox-${{ matrix.session.session }}-${{
hashFiles('**/poetry.lock') }}-${{ hashFiles('**/noxfile.py') }}-3
hashFiles('**/poetry.lock') }}-${{ hashFiles('**/noxfile.py') }}-4

- run: pip install poetry nox nox-poetry
- run: nox -r -t tests -s "${{ matrix.session.session }}"
Expand Down
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: Optional[GraphQLFilter[str]] = None,
) -> List[Author]:
return [Author(name="F. Scott Fitzgerald")]


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


@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):
def run():
coroutine = schema.execute(query)

return asyncio.run(coroutine)

result = benchmark(run)

assert not result.errors

0 comments on commit 095463d

Please sign in to comment.