Skip to content
Closed
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.10
rev: v0.14.0
hooks:
- id: ruff-format
exclude: ^tests/\w+/snapshots/
Expand Down Expand Up @@ -31,7 +31,7 @@ repos:
args: ["--branch", "main"]

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.19.1
rev: 1.20.0
hooks:
- id: blacken-docs
args: [--skip-errors]
Expand Down
2 changes: 1 addition & 1 deletion strawberry/chalice/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import warnings
from typing import TYPE_CHECKING, Optional, Union

from chalice.app import Request, Response
from lia import ChaliceHTTPRequestAdapter, HTTPException

from chalice.app import Request, Response
from strawberry.http.sync_base_view import SyncBaseHTTPView
from strawberry.http.temporal_response import TemporalResponse
from strawberry.http.typevars import Context, RootValue
Expand Down
4 changes: 2 additions & 2 deletions strawberry/channels/handlers/http_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from typing_extensions import TypeGuard, assert_never
from urllib.parse import parse_qs

from channels.db import database_sync_to_async
from channels.generic.http import AsyncHttpConsumer
from django.conf import settings
from django.core.files import uploadhandler
from django.http.multipartparser import MultiPartParser
from lia import AsyncHTTPRequestAdapter, FormData, HTTPException, SyncHTTPRequestAdapter

from channels.db import database_sync_to_async
from channels.generic.http import AsyncHttpConsumer
from strawberry.http.async_base_view import AsyncBaseHTTPView
from strawberry.http.sync_base_view import SyncBaseHTTPView
from strawberry.http.temporal_response import TemporalResponse
Expand Down
3 changes: 1 addition & 2 deletions strawberry/channels/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

from typing import TYPE_CHECKING, Optional

from django.urls import re_path

from channels.routing import ProtocolTypeRouter, URLRouter
from django.urls import re_path

from .handlers.http_handler import GraphQLHTTPConsumer
from .handlers.ws_handler import GraphQLWSConsumer
Expand Down
2 changes: 1 addition & 1 deletion strawberry/channels/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
Union,
)

from channels.testing.websocket import WebsocketCommunicator
from graphql import GraphQLError, GraphQLFormattedError

from channels.testing.websocket import WebsocketCommunicator
from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL
from strawberry.subscriptions.protocols.graphql_transport_ws import (
types as transport_ws_types,
Expand Down
6 changes: 3 additions & 3 deletions strawberry/fastapi/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
)
from typing_extensions import TypeGuard

from fastapi.datastructures import Default
from fastapi.routing import APIRoute
from fastapi.utils import generate_unique_id
from lia import HTTPException, StarletteRequestAdapter
from starlette import status
from starlette.background import BackgroundTasks # noqa: TC002
Expand All @@ -27,9 +30,6 @@
from starlette.websockets import WebSocket

from fastapi import APIRouter, Depends, params
from fastapi.datastructures import Default
from fastapi.routing import APIRoute
from fastapi.utils import generate_unique_id
from strawberry.asgi import ASGIWebSocketAdapter
from strawberry.exceptions import InvalidCustomContext
from strawberry.fastapi.context import BaseContext, CustomContext
Expand Down
2 changes: 1 addition & 1 deletion strawberry/federation/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def field(
# This init parameter is used by PyRight to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init: Literal[True, False, None] = None,
init: Optional[Literal[True, False]] = None,
) -> Any:
from .schema_directives import (
Authenticated,
Expand Down
1 change: 1 addition & 0 deletions strawberry/flask/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

if TYPE_CHECKING:
from flask.typing import ResponseReturnValue

from strawberry.http import GraphQLHTTPResponse
from strawberry.http.ides import GraphQL_IDE
from strawberry.schema.base import BaseSchema
Expand Down
19 changes: 10 additions & 9 deletions strawberry/litestar/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
from typing_extensions import TypeGuard

from lia import HTTPException, LitestarRequestAdapter
from litestar.background_tasks import BackgroundTasks
from litestar.di import Provide
from litestar.exceptions import (
NotFoundException,
ValidationException,
WebSocketDisconnect,
)
from litestar.response.streaming import Stream
from litestar.status_codes import HTTP_200_OK
from msgspec import Struct

from litestar import (
Expand All @@ -29,15 +38,6 @@
post,
websocket,
)
from litestar.background_tasks import BackgroundTasks
from litestar.di import Provide
from litestar.exceptions import (
NotFoundException,
ValidationException,
WebSocketDisconnect,
)
from litestar.response.streaming import Stream
from litestar.status_codes import HTTP_200_OK
from strawberry.exceptions import InvalidCustomContext
from strawberry.http.async_base_view import (
AsyncBaseHTTPView,
Expand All @@ -55,6 +55,7 @@
from collections.abc import AsyncGenerator, AsyncIterator, Mapping, Sequence

from litestar.types import AnyCallable, Dependencies

from strawberry.http import GraphQLHTTPResponse
from strawberry.http.ides import GraphQL_IDE
from strawberry.schema import BaseSchema
Expand Down
3 changes: 2 additions & 1 deletion strawberry/quart/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from typing_extensions import TypeGuard

from lia import HTTPException, QuartHTTPRequestAdapter
from quart.ctx import has_websocket_context

from quart import Request, Response, Websocket, request, websocket
from quart.ctx import has_websocket_context
from quart.views import View
from strawberry.http.async_base_view import (
AsyncBaseHTTPView,
Expand All @@ -26,6 +26,7 @@

if TYPE_CHECKING:
from quart.typing import ResponseReturnValue

from strawberry.http import GraphQLHTTPResponse
from strawberry.schema.base import BaseSchema

Expand Down
2 changes: 1 addition & 1 deletion strawberry/relay/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def connection(
# This init parameter is used by pyright to determine whether this field
# is added in the constructor or not. It is not used to change
# any behaviour at the moment.
init: Literal[True, False, None] = None,
init: Optional[Literal[True, False]] = None,
) -> Any:
"""Annotate a property or a method to create a relay connection field.

Expand Down
1 change: 1 addition & 0 deletions strawberry/sanic/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing_extensions import TypedDict

from sanic.request import Request

from strawberry.http.temporal_response import TemporalResponse


Expand Down
2 changes: 1 addition & 1 deletion strawberry/sanic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from typing_extensions import TypeGuard

from lia import HTTPException, SanicHTTPRequestAdapter

from sanic.request import Request
from sanic.response import HTTPResponse, html

from sanic.views import HTTPMethodView
from strawberry.http.async_base_view import AsyncBaseHTTPView
from strawberry.http.temporal_response import TemporalResponse
Expand Down
2 changes: 1 addition & 1 deletion strawberry/types/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def field(
# This init parameter is used by PyRight to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init: Literal[True, False, None] = None,
init: Optional[Literal[True, False]] = None,
) -> Any:
"""Annotates a method or property as a GraphQL field.

Expand Down
4 changes: 2 additions & 2 deletions strawberry/types/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def mutation(
# This init parameter is used by PyRight to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init: Literal[True, False, None] = None,
init: Optional[Literal[True, False]] = None,
) -> Any:
"""Annotates a method or property as a GraphQL mutation.

Expand Down Expand Up @@ -291,7 +291,7 @@ def subscription(
directives: Optional[Sequence[object]] = (),
extensions: Optional[list[FieldExtension]] = None,
graphql_type: Optional[Any] = None,
init: Literal[True, False, None] = None,
init: Optional[Literal[True, False]] = None,
) -> Any:
"""Annotates a method or property as a GraphQL subscription.

Expand Down
20 changes: 13 additions & 7 deletions tests/fastapi/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ def test_base_context():


def test_with_explicit_class_context_getter():
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient

from fastapi import Depends, FastAPI
from strawberry.fastapi import BaseContext, GraphQLRouter

@strawberry.type
Expand Down Expand Up @@ -58,8 +59,9 @@ def get_context(custom_context: CustomContext = Depends(custom_context_dependenc


def test_with_implicit_class_context_getter():
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient

from fastapi import Depends, FastAPI
from strawberry.fastapi import BaseContext, GraphQLRouter

@strawberry.type
Expand Down Expand Up @@ -92,8 +94,9 @@ def get_context(custom_context: CustomContext = Depends()):


def test_with_dict_context_getter():
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient

from fastapi import Depends, FastAPI
from strawberry.fastapi import GraphQLRouter

@strawberry.type
Expand Down Expand Up @@ -124,8 +127,9 @@ def get_context(value: str = Depends(custom_context_dependency)) -> dict[str, st


def test_without_context_getter():
from fastapi import FastAPI
from fastapi.testclient import TestClient

from fastapi import FastAPI
from strawberry.fastapi import GraphQLRouter

@strawberry.type
Expand All @@ -149,8 +153,9 @@ def abc(self, info: strawberry.Info) -> str:


def test_with_invalid_context_getter():
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient

from fastapi import Depends, FastAPI
from strawberry.fastapi import GraphQLRouter

@strawberry.type
Expand Down Expand Up @@ -184,8 +189,9 @@ def get_context(value: str = Depends(custom_context_dependency)) -> str:


def test_class_context_injects_connection_params_over_transport_ws():
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient

from fastapi import Depends, FastAPI
from strawberry.fastapi import BaseContext, GraphQLRouter

@strawberry.type
Expand Down Expand Up @@ -256,10 +262,10 @@ def get_context(context: Context = Depends()) -> Context:


def test_class_context_injects_connection_params_over_ws():
from fastapi.testclient import TestClient
from starlette.websockets import WebSocketDisconnect

from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
from strawberry.fastapi import BaseContext, GraphQLRouter

@strawberry.type
Expand Down
3 changes: 2 additions & 1 deletion tests/http/clients/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
from typing import Any, Optional, Union
from typing_extensions import Literal

from aiohttp import web
from aiohttp.client_ws import ClientWebSocketResponse
from aiohttp.http_websocket import WSMsgType
from aiohttp.test_utils import TestClient, TestServer

from aiohttp import web
from strawberry.aiohttp.views import GraphQLView as BaseGraphQLView
from strawberry.http import GraphQLHTTPResponse
from strawberry.http.ides import GraphQL_IDE
Expand Down
1 change: 1 addition & 0 deletions tests/http/clients/chalice.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from chalice.app import Chalice
from chalice.app import Request as ChaliceRequest
from chalice.test import Client

from strawberry import Schema
from strawberry.chalice.views import GraphQLView as BaseGraphQLView
from strawberry.http import GraphQLHTTPResponse
Expand Down
3 changes: 2 additions & 1 deletion tests/http/clients/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from typing import Any, Optional
from typing_extensions import Literal

from fastapi import BackgroundTasks, Depends, FastAPI, Request, WebSocket
from fastapi.testclient import TestClient

from fastapi import BackgroundTasks, Depends, FastAPI, Request, WebSocket
from strawberry.fastapi import GraphQLRouter as BaseGraphQLRouter
from strawberry.http import GraphQLHTTPResponse
from strawberry.http.ides import GraphQL_IDE
Expand Down
3 changes: 2 additions & 1 deletion tests/http/clients/litestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
from typing import Any, Optional
from typing_extensions import Literal

from litestar import Litestar, Request
from litestar.exceptions import WebSocketDisconnect
from litestar.testing import TestClient
from litestar.testing.websocket_test_session import WebSocketTestSession

from litestar import Litestar, Request
from strawberry.http import GraphQLHTTPResponse
from strawberry.http.ides import GraphQL_IDE
from strawberry.litestar import make_graphql_controller
Expand Down
2 changes: 1 addition & 1 deletion tests/http/clients/quart.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from typing import Any, Optional, Union
from typing_extensions import Literal

from quart.datastructures import FileStorage
from starlette.testclient import TestClient
from starlette.types import Receive, Scope, Send

from quart import Quart
from quart import Request as QuartRequest
from quart import Response as QuartResponse
from quart import Websocket as QuartWebsocket
from quart.datastructures import FileStorage
from strawberry.http import GraphQLHTTPResponse
from strawberry.http.ides import GraphQL_IDE
from strawberry.quart.views import GraphQLView as BaseGraphQLView
Expand Down
3 changes: 2 additions & 1 deletion tests/http/clients/sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from typing import Any, Optional
from typing_extensions import Literal

from sanic import Sanic
from sanic.request import Request as SanicRequest

from sanic import Sanic
from strawberry.http import GraphQLHTTPResponse
from strawberry.http.ides import GraphQL_IDE
from strawberry.http.temporal_response import TemporalResponse
Expand Down
3 changes: 2 additions & 1 deletion tests/litestar/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Any

from litestar import Litestar, Request
from litestar.di import Provide

from litestar import Litestar, Request
from strawberry.litestar import make_graphql_controller
from tests.views.schema import schema

Expand Down
2 changes: 2 additions & 0 deletions tests/litestar/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@pytest.fixture
def test_client():
from litestar.testing import TestClient

from tests.litestar.app import create_app

app = create_app()
Expand All @@ -13,6 +14,7 @@ def test_client():
@pytest.fixture
def test_client_keep_alive():
from litestar.testing import TestClient

from tests.litestar.app import create_app

app = create_app(keep_alive=True, keep_alive_interval=0.1)
Expand Down
Loading
Loading