Skip to content

Commit

Permalink
chore(deps): Update dev dependencies and fix typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bellini666 committed Oct 12, 2024
1 parent 54c0708 commit 73fdf0a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 37 deletions.
59 changes: 30 additions & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion strawberry_django/fields/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def _resolve_array_field_type(model_field: Field):
return List[_resolve_array_field_type(model_field.base_field)]

base_field = field_type_map.get(type(model_field), NotImplemented)
if base_field is NotImplemented:
if base_field is NotImplemented: # type: ignore
raise NotImplementedError(
f"GraphQL type for model field '{model_field}' has not been implemented",
)
Expand Down
2 changes: 1 addition & 1 deletion strawberry_django/mutations/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def resolve_type(

name = capitalize_first(to_camel_case(self.python_name))
resolved = Annotated[
Union[types_], # type: ignore
Union[types_],
strawberry.union(f"{name}Payload"),
]
self.type_annotation = StrawberryAnnotation(
Expand Down
21 changes: 18 additions & 3 deletions strawberry_django/test/client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import contextlib
import warnings
from typing import Any, Awaitable, Dict, Optional, cast

from asgiref.sync import sync_to_async
from django.contrib.auth.base_user import AbstractBaseUser
from django.test.client import AsyncClient, Client # type: ignore
from strawberry.test import BaseGraphQLTestClient
from strawberry.test.client import Response
from typing_extensions import override


class TestClient(BaseGraphQLTestClient):
Expand Down Expand Up @@ -49,13 +51,15 @@ def __init__(self, path: str, client: Optional[AsyncClient] = None):
def client(self) -> AsyncClient:
return self._client

@override
async def query(
self,
query: str,
variables: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, object]] = None,
asserts_errors: Optional[bool] = True,
asserts_errors: Optional[bool] = None,
files: Optional[Dict[str, object]] = None,
assert_no_errors: Optional[bool] = True,
) -> Response:
body = self._build_body(query, variables, files)

Expand All @@ -67,8 +71,19 @@ async def query(
data=data.get("data"),
extensions=data.get("extensions"),
)
if asserts_errors:
assert response.errors is None, response.errors

if asserts_errors is not None:
warnings.warn(
"The `asserts_errors` argument has been renamed to `assert_no_errors`",
DeprecationWarning,
stacklevel=2,
)

assert_no_errors = (
assert_no_errors if asserts_errors is None else asserts_errors
)
if assert_no_errors:
assert response.errors is None

return response

Expand Down
21 changes: 18 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import contextvars
import dataclasses
import inspect
import warnings
from typing import Any, Dict, Optional, Union

import strawberry
Expand All @@ -14,6 +15,7 @@
from django.test.utils import CaptureQueriesContext
from strawberry.test.client import Response
from strawberry.utils.inspect import in_async_context
from typing_extensions import override

from strawberry_django.optimizer import DjangoOptimizerExtension
from strawberry_django.test.client import TestClient
Expand Down Expand Up @@ -147,13 +149,15 @@ def request(
**kwargs, # type: ignore
)

@override
def query(
self,
query: str,
variables: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, object]] = None,
asserts_errors: Optional[bool] = True,
asserts_errors: Optional[bool] = None,
files: Optional[Dict[str, object]] = None,
assert_no_errors: Optional[bool] = True,
) -> Response:
body = self._build_body(query, variables, files)

Expand All @@ -168,7 +172,18 @@ def query(
data=data.get("data"),
extensions=data.get("extensions"),
)
if asserts_errors:
assert response.errors is None, response.errors

if asserts_errors is not None:
warnings.warn(
"The `asserts_errors` argument has been renamed to `assert_no_errors`",
DeprecationWarning,
stacklevel=2,
)

assert_no_errors = (
assert_no_errors if asserts_errors is None else asserts_errors
)
if assert_no_errors:
assert response.errors is None

return response

0 comments on commit 73fdf0a

Please sign in to comment.