From ed323d68963d52cc75081d403aee01ab68197a29 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Mon, 24 Jun 2024 09:42:55 +0200 Subject: [PATCH 1/4] Add benchmark --- tests/benchmarks/test_generic_input.py | 75 ++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/benchmarks/test_generic_input.py diff --git a/tests/benchmarks/test_generic_input.py b/tests/benchmarks/test_generic_input.py new file mode 100644 index 0000000000..45ac38bd98 --- /dev/null +++ b/tests/benchmarks/test_generic_input.py @@ -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]: + 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): + def run(): + coroutine = schema.execute(query) + + return asyncio.run(coroutine) + + result = benchmark(run) + + assert not result.errors From bbbe164b0f47ff6fd2fb9c6c3d1b7a2d26f1c7b2 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Mon, 24 Jun 2024 21:01:37 +0200 Subject: [PATCH 2/4] Bump cache? --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f7111d5a8d..71219aab13 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 }}" From 1229c9bd94f7cf3239af985b6e8586f1d4159d13 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Mon, 24 Jun 2024 21:10:38 +0200 Subject: [PATCH 3/4] Fix typing issue --- tests/benchmarks/test_generic_input.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/benchmarks/test_generic_input.py b/tests/benchmarks/test_generic_input.py index 45ac38bd98..5124466112 100644 --- a/tests/benchmarks/test_generic_input.py +++ b/tests/benchmarks/test_generic_input.py @@ -35,7 +35,7 @@ class Book: @strawberry.field async def authors( self, - name: GraphQLFilter[str] | None = None, + name: Optional[GraphQLFilter[str]] = None, ) -> List[Author]: return [Author(name="F. Scott Fitzgerald")] From d98578ae6343cfdc4601510bd0f60fd731cd4056 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Mon, 24 Jun 2024 21:47:55 +0200 Subject: [PATCH 4/4] Make test smaller --- tests/benchmarks/test_generic_input.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/benchmarks/test_generic_input.py b/tests/benchmarks/test_generic_input.py index 5124466112..bc937c4605 100644 --- a/tests/benchmarks/test_generic_input.py +++ b/tests/benchmarks/test_generic_input.py @@ -43,7 +43,7 @@ async def authors( def get_books(): return [ Book(title="The Great Gatsby"), - ] * 10000 + ] * 1000 @strawberry.type