strawberry-graphql 0.279.0.dev1754156227__py3-none-any.whl → 0.280.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. strawberry/__init__.py +1 -2
  2. strawberry/aiohttp/views.py +2 -48
  3. strawberry/asgi/__init__.py +2 -37
  4. strawberry/chalice/views.py +7 -75
  5. strawberry/channels/handlers/http_handler.py +30 -6
  6. strawberry/cli/commands/upgrade/__init__.py +2 -0
  7. strawberry/codemods/__init__.py +9 -0
  8. strawberry/codemods/maybe_optional.py +118 -0
  9. strawberry/django/views.py +4 -73
  10. strawberry/experimental/pydantic/_compat.py +1 -0
  11. strawberry/experimental/pydantic/error_type.py +1 -0
  12. strawberry/experimental/pydantic/fields.py +1 -0
  13. strawberry/experimental/pydantic/utils.py +1 -0
  14. strawberry/fastapi/router.py +8 -4
  15. strawberry/flask/views.py +4 -74
  16. strawberry/http/async_base_view.py +5 -31
  17. strawberry/http/base.py +2 -1
  18. strawberry/http/exceptions.py +5 -7
  19. strawberry/http/sync_base_view.py +1 -34
  20. strawberry/litestar/controller.py +1 -39
  21. strawberry/quart/views.py +3 -33
  22. strawberry/sanic/views.py +4 -43
  23. strawberry/schema/schema.py +2 -0
  24. strawberry/schema/schema_converter.py +7 -0
  25. strawberry/schema/validation_rules/maybe_null.py +136 -0
  26. strawberry/types/arguments.py +16 -2
  27. strawberry/types/maybe.py +1 -1
  28. {strawberry_graphql-0.279.0.dev1754156227.dist-info → strawberry_graphql-0.280.0.dist-info}/METADATA +2 -1
  29. {strawberry_graphql-0.279.0.dev1754156227.dist-info → strawberry_graphql-0.280.0.dist-info}/RECORD +32 -34
  30. strawberry/pydantic/__init__.py +0 -22
  31. strawberry/pydantic/error.py +0 -51
  32. strawberry/pydantic/fields.py +0 -202
  33. strawberry/pydantic/object_type.py +0 -348
  34. {strawberry_graphql-0.279.0.dev1754156227.dist-info → strawberry_graphql-0.280.0.dist-info}/LICENSE +0 -0
  35. {strawberry_graphql-0.279.0.dev1754156227.dist-info → strawberry_graphql-0.280.0.dist-info}/WHEEL +0 -0
  36. {strawberry_graphql-0.279.0.dev1754156227.dist-info → strawberry_graphql-0.280.0.dist-info}/entry_points.txt +0 -0
strawberry/__init__.py CHANGED
@@ -4,7 +4,7 @@ Strawberry is a Python library for GraphQL that aims to stay close to the GraphQ
4
4
  specification and allow for a more natural way of defining GraphQL schemas.
5
5
  """
6
6
 
7
- from . import experimental, federation, pydantic, relay
7
+ from . import experimental, federation, relay
8
8
  from .directive import directive, directive_field
9
9
  from .parent import Parent
10
10
  from .permission import BasePermission
@@ -54,7 +54,6 @@ __all__ = [
54
54
  "interface",
55
55
  "lazy",
56
56
  "mutation",
57
- "pydantic",
58
57
  "relay",
59
58
  "scalar",
60
59
  "schema_directive",
@@ -3,32 +3,27 @@ from __future__ import annotations
3
3
  import asyncio
4
4
  import warnings
5
5
  from datetime import timedelta
6
- from io import BytesIO
7
6
  from json.decoder import JSONDecodeError
8
7
  from typing import (
9
8
  TYPE_CHECKING,
10
- Any,
11
9
  Callable,
12
10
  Optional,
13
11
  Union,
14
- cast,
15
12
  )
16
13
  from typing_extensions import TypeGuard
17
14
 
15
+ from lia import AiohttpHTTPRequestAdapter, HTTPException
16
+
18
17
  from aiohttp import ClientConnectionResetError, http, web
19
- from aiohttp.multipart import BodyPartReader
20
18
  from strawberry.http.async_base_view import (
21
19
  AsyncBaseHTTPView,
22
- AsyncHTTPRequestAdapter,
23
20
  AsyncWebSocketAdapter,
24
21
  )
25
22
  from strawberry.http.exceptions import (
26
- HTTPException,
27
23
  NonJsonMessageReceived,
28
24
  NonTextMessageReceived,
29
25
  WebSocketDisconnected,
30
26
  )
31
- from strawberry.http.types import FormData, HTTPMethod, QueryParams
32
27
  from strawberry.http.typevars import (
33
28
  Context,
34
29
  RootValue,
@@ -43,47 +38,6 @@ if TYPE_CHECKING:
43
38
  from strawberry.schema import BaseSchema
44
39
 
45
40
 
46
- class AiohttpHTTPRequestAdapter(AsyncHTTPRequestAdapter):
47
- def __init__(self, request: web.Request) -> None:
48
- self.request = request
49
-
50
- @property
51
- def query_params(self) -> QueryParams:
52
- return self.request.query.copy() # type: ignore[attr-defined]
53
-
54
- async def get_body(self) -> str:
55
- return (await self.request.content.read()).decode()
56
-
57
- @property
58
- def method(self) -> HTTPMethod:
59
- return cast("HTTPMethod", self.request.method.upper())
60
-
61
- @property
62
- def headers(self) -> Mapping[str, str]:
63
- return self.request.headers
64
-
65
- async def get_form_data(self) -> FormData:
66
- reader = await self.request.multipart()
67
-
68
- data: dict[str, Any] = {}
69
- files: dict[str, Any] = {}
70
-
71
- while field := await reader.next():
72
- assert isinstance(field, BodyPartReader)
73
- assert field.name
74
-
75
- if field.filename:
76
- files[field.name] = BytesIO(await field.read(decode=False))
77
- else:
78
- data[field.name] = await field.text()
79
-
80
- return FormData(files=files, form=data)
81
-
82
- @property
83
- def content_type(self) -> Optional[str]:
84
- return self.headers.get("content-type")
85
-
86
-
87
41
  class AiohttpWebSocketAdapter(AsyncWebSocketAdapter):
88
42
  def __init__(
89
43
  self, view: AsyncBaseHTTPView, request: web.Request, ws: web.WebSocketResponse
@@ -8,10 +8,10 @@ from typing import (
8
8
  Callable,
9
9
  Optional,
10
10
  Union,
11
- cast,
12
11
  )
13
12
  from typing_extensions import TypeGuard
14
13
 
14
+ from lia import HTTPException, StarletteRequestAdapter
15
15
  from starlette import status
16
16
  from starlette.requests import Request
17
17
  from starlette.responses import (
@@ -24,16 +24,13 @@ from starlette.websockets import WebSocket, WebSocketDisconnect, WebSocketState
24
24
 
25
25
  from strawberry.http.async_base_view import (
26
26
  AsyncBaseHTTPView,
27
- AsyncHTTPRequestAdapter,
28
27
  AsyncWebSocketAdapter,
29
28
  )
30
29
  from strawberry.http.exceptions import (
31
- HTTPException,
32
30
  NonJsonMessageReceived,
33
31
  NonTextMessageReceived,
34
32
  WebSocketDisconnected,
35
33
  )
36
- from strawberry.http.types import FormData, HTTPMethod, QueryParams
37
34
  from strawberry.http.typevars import (
38
35
  Context,
39
36
  RootValue,
@@ -50,38 +47,6 @@ if TYPE_CHECKING:
50
47
  from strawberry.schema import BaseSchema
51
48
 
52
49
 
53
- class ASGIRequestAdapter(AsyncHTTPRequestAdapter):
54
- def __init__(self, request: Request) -> None:
55
- self.request = request
56
-
57
- @property
58
- def query_params(self) -> QueryParams:
59
- return self.request.query_params
60
-
61
- @property
62
- def method(self) -> HTTPMethod:
63
- return cast("HTTPMethod", self.request.method.upper())
64
-
65
- @property
66
- def headers(self) -> Mapping[str, str]:
67
- return self.request.headers
68
-
69
- @property
70
- def content_type(self) -> Optional[str]:
71
- return self.request.headers.get("content-type")
72
-
73
- async def get_body(self) -> bytes:
74
- return await self.request.body()
75
-
76
- async def get_form_data(self) -> FormData:
77
- multipart_data = await self.request.form()
78
-
79
- return FormData(
80
- files=multipart_data,
81
- form=multipart_data,
82
- )
83
-
84
-
85
50
  class ASGIWebSocketAdapter(AsyncWebSocketAdapter):
86
51
  def __init__(
87
52
  self, view: AsyncBaseHTTPView, request: WebSocket, response: WebSocket
@@ -127,7 +92,7 @@ class GraphQL(
127
92
  ]
128
93
  ):
129
94
  allow_queries_via_get = True
130
- request_adapter_class = ASGIRequestAdapter
95
+ request_adapter_class = StarletteRequestAdapter
131
96
  websocket_adapter_class = ASGIWebSocketAdapter
132
97
 
133
98
  def __init__(
@@ -1,56 +1,21 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import warnings
4
- from typing import TYPE_CHECKING, Any, Optional, Union, cast
4
+ from typing import TYPE_CHECKING, Optional, Union
5
+
6
+ from lia import ChaliceHTTPRequestAdapter, HTTPException
5
7
 
6
8
  from chalice.app import Request, Response
7
- from strawberry.http.exceptions import HTTPException
8
- from strawberry.http.sync_base_view import SyncBaseHTTPView, SyncHTTPRequestAdapter
9
+ from strawberry.http.sync_base_view import SyncBaseHTTPView
9
10
  from strawberry.http.temporal_response import TemporalResponse
10
11
  from strawberry.http.typevars import Context, RootValue
11
12
 
12
13
  if TYPE_CHECKING:
13
- from collections.abc import Mapping
14
-
15
14
  from strawberry.http import GraphQLHTTPResponse
16
15
  from strawberry.http.ides import GraphQL_IDE
17
- from strawberry.http.types import HTTPMethod, QueryParams
18
16
  from strawberry.schema import BaseSchema
19
17
 
20
18
 
21
- class ChaliceHTTPRequestAdapter(SyncHTTPRequestAdapter):
22
- def __init__(self, request: Request) -> None:
23
- self.request = request
24
-
25
- @property
26
- def query_params(self) -> QueryParams:
27
- return self.request.query_params or {}
28
-
29
- @property
30
- def body(self) -> Union[str, bytes]:
31
- return self.request.raw_body
32
-
33
- @property
34
- def method(self) -> HTTPMethod:
35
- return cast("HTTPMethod", self.request.method.upper())
36
-
37
- @property
38
- def headers(self) -> Mapping[str, str]:
39
- return self.request.headers
40
-
41
- @property
42
- def post_data(self) -> Mapping[str, Union[str, bytes]]:
43
- raise NotImplementedError
44
-
45
- @property
46
- def files(self) -> Mapping[str, Any]:
47
- raise NotImplementedError
48
-
49
- @property
50
- def content_type(self) -> Optional[str]:
51
- return self.request.headers.get("Content-Type", None)
52
-
53
-
54
19
  class GraphQLView(
55
20
  SyncBaseHTTPView[Request, Response, TemporalResponse, Context, RootValue]
56
21
  ):
@@ -88,28 +53,6 @@ class GraphQLView(
88
53
  def get_sub_response(self, request: Request) -> TemporalResponse:
89
54
  return TemporalResponse()
90
55
 
91
- @staticmethod
92
- def error_response(
93
- message: str,
94
- error_code: str,
95
- http_status_code: int,
96
- headers: Optional[dict[str, str | list[str]]] = None,
97
- ) -> Response:
98
- """A wrapper for error responses.
99
-
100
- Args:
101
- message: The error message.
102
- error_code: The error code.
103
- http_status_code: The HTTP status code.
104
- headers: The headers to include in the response.
105
-
106
- Returns:
107
- An errors response.
108
- """
109
- body = {"Code": error_code, "Message": message}
110
-
111
- return Response(body=body, status_code=http_status_code, headers=headers)
112
-
113
56
  def get_context(self, request: Request, response: TemporalResponse) -> Context:
114
57
  return {"request": request, "response": response} # type: ignore
115
58
 
@@ -136,20 +79,9 @@ class GraphQLView(
136
79
  try:
137
80
  return self.run(request=request)
138
81
  except HTTPException as e:
139
- error_code_map = {
140
- 400: "BadRequestError",
141
- 401: "UnauthorizedError",
142
- 403: "ForbiddenError",
143
- 404: "NotFoundError",
144
- 409: "ConflictError",
145
- 429: "TooManyRequestsError",
146
- 500: "ChaliceViewError",
147
- }
148
-
149
- return self.error_response(
150
- error_code=error_code_map.get(e.status_code, "ChaliceViewError"),
151
- message=e.reason,
152
- http_status_code=e.status_code,
82
+ return Response(
83
+ body=e.reason,
84
+ status_code=e.status_code,
153
85
  )
154
86
 
155
87
 
@@ -12,14 +12,13 @@ from urllib.parse import parse_qs
12
12
  from django.conf import settings
13
13
  from django.core.files import uploadhandler
14
14
  from django.http.multipartparser import MultiPartParser
15
+ from lia import AsyncHTTPRequestAdapter, FormData, HTTPException, SyncHTTPRequestAdapter
15
16
 
16
17
  from channels.db import database_sync_to_async
17
18
  from channels.generic.http import AsyncHttpConsumer
18
- from strawberry.http.async_base_view import AsyncBaseHTTPView, AsyncHTTPRequestAdapter
19
- from strawberry.http.exceptions import HTTPException
20
- from strawberry.http.sync_base_view import SyncBaseHTTPView, SyncHTTPRequestAdapter
19
+ from strawberry.http.async_base_view import AsyncBaseHTTPView
20
+ from strawberry.http.sync_base_view import SyncBaseHTTPView
21
21
  from strawberry.http.temporal_response import TemporalResponse
22
- from strawberry.http.types import FormData
23
22
  from strawberry.http.typevars import Context, RootValue
24
23
  from strawberry.types.unset import UNSET
25
24
 
@@ -127,6 +126,28 @@ class BaseChannelsRequestAdapter:
127
126
  def content_type(self) -> Optional[str]:
128
127
  return self.request.content_type
129
128
 
129
+ @property
130
+ def url(self) -> str:
131
+ scheme = self.request.consumer.scope["scheme"]
132
+ host = self.headers.get("host", "localhost")
133
+ path = self.request.consumer.scope["path"]
134
+ query_string = self.request.consumer.scope["query_string"]
135
+ url = f"{scheme}://{host}{path}"
136
+ if query_string:
137
+ url += f"?{query_string.decode()}"
138
+ return url
139
+
140
+ @property
141
+ def cookies(self) -> Mapping[str, str]:
142
+ cookie_header = self.headers.get("cookie", "")
143
+ cookies = {}
144
+ if cookie_header:
145
+ for cookie in cookie_header.split(";"):
146
+ if "=" in cookie:
147
+ key, value = cookie.split("=", 1)
148
+ cookies[key.strip()] = value.strip()
149
+ return cookies
150
+
130
151
 
131
152
  class ChannelsRequestAdapter(BaseChannelsRequestAdapter, AsyncHTTPRequestAdapter):
132
153
  async def get_body(self) -> bytes:
@@ -143,11 +164,14 @@ class SyncChannelsRequestAdapter(BaseChannelsRequestAdapter, SyncHTTPRequestAdap
143
164
 
144
165
  @property
145
166
  def post_data(self) -> Mapping[str, Union[str, bytes]]:
146
- return self.request.form_data["form"]
167
+ return self.request.form_data.form
147
168
 
148
169
  @property
149
170
  def files(self) -> Mapping[str, Any]:
150
- return self.request.form_data["files"]
171
+ return self.request.form_data.files
172
+
173
+ def get_form_data(self) -> FormData:
174
+ return self.request.form_data
151
175
 
152
176
 
153
177
  class BaseGraphQLHTTPConsumer(ChannelsConsumer, AsyncHttpConsumer):
@@ -10,6 +10,7 @@ from libcst.codemod import CodemodContext
10
10
 
11
11
  from strawberry.cli.app import app
12
12
  from strawberry.codemods.annotated_unions import ConvertUnionToAnnotatedUnion
13
+ from strawberry.codemods.maybe_optional import ConvertMaybeToOptional
13
14
  from strawberry.codemods.update_imports import UpdateImportsCodemod
14
15
 
15
16
  from ._run_codemod import run_codemod
@@ -17,6 +18,7 @@ from ._run_codemod import run_codemod
17
18
  codemods = {
18
19
  "annotated-union": ConvertUnionToAnnotatedUnion,
19
20
  "update-imports": UpdateImportsCodemod,
21
+ "maybe-optional": ConvertMaybeToOptional,
20
22
  }
21
23
 
22
24
 
@@ -0,0 +1,9 @@
1
+ from .annotated_unions import ConvertUnionToAnnotatedUnion
2
+ from .maybe_optional import ConvertMaybeToOptional
3
+ from .update_imports import UpdateImportsCodemod
4
+
5
+ __all__ = [
6
+ "ConvertMaybeToOptional",
7
+ "ConvertUnionToAnnotatedUnion",
8
+ "UpdateImportsCodemod",
9
+ ]
@@ -0,0 +1,118 @@
1
+ from __future__ import annotations
2
+
3
+ import libcst as cst
4
+ import libcst.matchers as m
5
+ from libcst._nodes.expression import BaseExpression # noqa: TC002
6
+ from libcst.codemod import CodemodContext, VisitorBasedCodemodCommand
7
+ from libcst.codemod.visitors import AddImportsVisitor
8
+
9
+
10
+ class ConvertMaybeToOptional(VisitorBasedCodemodCommand):
11
+ DESCRIPTION: str = (
12
+ "Converts strawberry.Maybe[T] to strawberry.Maybe[T | None] "
13
+ "to match the new Maybe type definition"
14
+ )
15
+
16
+ def __init__(
17
+ self,
18
+ context: CodemodContext,
19
+ use_pipe_syntax: bool = True, # Default to pipe syntax for modern Python
20
+ ) -> None:
21
+ self.use_pipe_syntax = use_pipe_syntax
22
+ super().__init__(context)
23
+
24
+ @m.leave(
25
+ m.Subscript(
26
+ value=m.Attribute(value=m.Name("strawberry"), attr=m.Name("Maybe"))
27
+ | m.Name("Maybe")
28
+ )
29
+ )
30
+ def leave_maybe_subscript(
31
+ self, original_node: cst.Subscript, updated_node: cst.Subscript
32
+ ) -> BaseExpression:
33
+ # Skip if it's not a strawberry.Maybe or imported Maybe
34
+ if isinstance(original_node.value, cst.Name):
35
+ # Check if this is an imported Maybe from strawberry
36
+ # For now, we'll assume any standalone "Maybe" is from strawberry
37
+ # In a more robust implementation, we'd track imports
38
+ pass
39
+
40
+ # Get the inner type
41
+ if isinstance(original_node.slice, (list, tuple)):
42
+ if len(original_node.slice) != 1:
43
+ return original_node
44
+ slice_element = original_node.slice[0]
45
+ else:
46
+ slice_element = original_node.slice
47
+
48
+ if not isinstance(slice_element, cst.SubscriptElement):
49
+ return original_node
50
+
51
+ if not isinstance(slice_element.slice, cst.Index):
52
+ return original_node
53
+
54
+ inner_type = slice_element.slice.value
55
+
56
+ # Check if the inner type already includes None
57
+ if self._already_includes_none(inner_type):
58
+ return original_node
59
+
60
+ # Create the new union type with None
61
+ new_type: BaseExpression
62
+ if self.use_pipe_syntax:
63
+ new_type = cst.BinaryOperation(
64
+ left=inner_type,
65
+ operator=cst.BitOr(
66
+ whitespace_before=cst.SimpleWhitespace(" "),
67
+ whitespace_after=cst.SimpleWhitespace(" "),
68
+ ),
69
+ right=cst.Name("None"),
70
+ )
71
+ else:
72
+ # Use Union[T, None] syntax
73
+ AddImportsVisitor.add_needed_import(self.context, "typing", "Union")
74
+ new_type = cst.Subscript(
75
+ value=cst.Name("Union"),
76
+ slice=[
77
+ cst.SubscriptElement(slice=cst.Index(value=inner_type)),
78
+ cst.SubscriptElement(slice=cst.Index(value=cst.Name("None"))),
79
+ ],
80
+ )
81
+
82
+ # Return the updated Maybe[T | None]
83
+ return updated_node.with_changes(
84
+ slice=[cst.SubscriptElement(slice=cst.Index(value=new_type))]
85
+ )
86
+
87
+ def _already_includes_none(self, node: BaseExpression) -> bool:
88
+ """Check if the type already includes None (e.g., T | None or Union[T, None])."""
89
+ # Check for T | None pattern
90
+ if isinstance(node, cst.BinaryOperation) and isinstance(
91
+ node.operator, cst.BitOr
92
+ ):
93
+ if isinstance(node.right, cst.Name) and node.right.value == "None":
94
+ return True
95
+ # Recursively check left side for chained unions
96
+ if self._already_includes_none(node.left):
97
+ return True
98
+
99
+ # Check for Union[..., None] pattern
100
+ if (
101
+ isinstance(node, cst.Subscript)
102
+ and isinstance(node.value, cst.Name)
103
+ and node.value.value == "Union"
104
+ ):
105
+ # Handle both list and tuple slice formats
106
+ slice_elements = (
107
+ node.slice if isinstance(node.slice, (list, tuple)) else [node.slice]
108
+ )
109
+ for element in slice_elements:
110
+ if (
111
+ isinstance(element, cst.SubscriptElement)
112
+ and isinstance(element.slice, cst.Index)
113
+ and isinstance(element.slice.value, cst.Name)
114
+ and element.slice.value.value == "None"
115
+ ):
116
+ return True
117
+
118
+ return False
@@ -8,7 +8,6 @@ from typing import (
8
8
  Callable,
9
9
  Optional,
10
10
  Union,
11
- cast,
12
11
  )
13
12
  from typing_extensions import TypeGuard
14
13
 
@@ -26,11 +25,10 @@ from django.template.exceptions import TemplateDoesNotExist
26
25
  from django.template.loader import render_to_string
27
26
  from django.utils.decorators import classonlymethod
28
27
  from django.views.generic import View
28
+ from lia import AsyncDjangoHTTPRequestAdapter, DjangoHTTPRequestAdapter, HTTPException
29
29
 
30
- from strawberry.http.async_base_view import AsyncBaseHTTPView, AsyncHTTPRequestAdapter
31
- from strawberry.http.exceptions import HTTPException
32
- from strawberry.http.sync_base_view import SyncBaseHTTPView, SyncHTTPRequestAdapter
33
- from strawberry.http.types import FormData, HTTPMethod, QueryParams
30
+ from strawberry.http.async_base_view import AsyncBaseHTTPView
31
+ from strawberry.http.sync_base_view import SyncBaseHTTPView
34
32
  from strawberry.http.typevars import (
35
33
  Context,
36
34
  RootValue,
@@ -39,7 +37,7 @@ from strawberry.http.typevars import (
39
37
  from .context import StrawberryDjangoContext
40
38
 
41
39
  if TYPE_CHECKING:
42
- from collections.abc import AsyncIterator, Mapping
40
+ from collections.abc import AsyncIterator
43
41
 
44
42
  from django.template.response import TemplateResponse
45
43
 
@@ -67,73 +65,6 @@ class TemporalHttpResponse(JsonResponse):
67
65
  )
68
66
 
69
67
 
70
- class DjangoHTTPRequestAdapter(SyncHTTPRequestAdapter):
71
- def __init__(self, request: HttpRequest) -> None:
72
- self.request = request
73
-
74
- @property
75
- def query_params(self) -> QueryParams:
76
- return self.request.GET.dict()
77
-
78
- @property
79
- def body(self) -> Union[str, bytes]:
80
- return self.request.body.decode()
81
-
82
- @property
83
- def method(self) -> HTTPMethod:
84
- assert self.request.method is not None
85
-
86
- return cast("HTTPMethod", self.request.method.upper())
87
-
88
- @property
89
- def headers(self) -> Mapping[str, str]:
90
- return self.request.headers
91
-
92
- @property
93
- def post_data(self) -> Mapping[str, Union[str, bytes]]:
94
- return self.request.POST
95
-
96
- @property
97
- def files(self) -> Mapping[str, Any]:
98
- return self.request.FILES
99
-
100
- @property
101
- def content_type(self) -> Optional[str]:
102
- return self.request.content_type
103
-
104
-
105
- class AsyncDjangoHTTPRequestAdapter(AsyncHTTPRequestAdapter):
106
- def __init__(self, request: HttpRequest) -> None:
107
- self.request = request
108
-
109
- @property
110
- def query_params(self) -> QueryParams:
111
- return self.request.GET.dict()
112
-
113
- @property
114
- def method(self) -> HTTPMethod:
115
- assert self.request.method is not None
116
-
117
- return cast("HTTPMethod", self.request.method.upper())
118
-
119
- @property
120
- def headers(self) -> Mapping[str, str]:
121
- return self.request.headers
122
-
123
- @property
124
- def content_type(self) -> Optional[str]:
125
- return self.headers.get("Content-type")
126
-
127
- async def get_body(self) -> str:
128
- return self.request.body.decode()
129
-
130
- async def get_form_data(self) -> FormData:
131
- return FormData(
132
- files=self.request.FILES,
133
- form=self.request.POST,
134
- )
135
-
136
-
137
68
  class BaseView:
138
69
  graphql_ide_html: str
139
70
 
@@ -8,6 +8,7 @@ from uuid import UUID
8
8
  import pydantic
9
9
  from pydantic import BaseModel
10
10
  from pydantic.version import VERSION as PYDANTIC_VERSION
11
+
11
12
  from strawberry.experimental.pydantic.exceptions import UnsupportedTypeError
12
13
 
13
14
  if TYPE_CHECKING:
@@ -12,6 +12,7 @@ from typing import (
12
12
  )
13
13
 
14
14
  from pydantic import BaseModel
15
+
15
16
  from strawberry.experimental.pydantic._compat import (
16
17
  CompatModelField,
17
18
  PydanticCompat,
@@ -2,6 +2,7 @@ import builtins
2
2
  from typing import Annotated, Any, Union
3
3
 
4
4
  from pydantic import BaseModel
5
+
5
6
  from strawberry.experimental.pydantic._compat import (
6
7
  PydanticCompat,
7
8
  get_args,
@@ -10,6 +10,7 @@ from typing import (
10
10
  )
11
11
 
12
12
  from pydantic import BaseModel
13
+
13
14
  from strawberry.experimental.pydantic._compat import (
14
15
  CompatModelField,
15
16
  PydanticCompat,
@@ -13,6 +13,7 @@ from typing import (
13
13
  )
14
14
  from typing_extensions import TypeGuard
15
15
 
16
+ from lia import HTTPException, StarletteRequestAdapter
16
17
  from starlette import status
17
18
  from starlette.background import BackgroundTasks # noqa: TC002
18
19
  from starlette.requests import HTTPConnection, Request
@@ -29,16 +30,19 @@ from fastapi import APIRouter, Depends, params
29
30
  from fastapi.datastructures import Default
30
31
  from fastapi.routing import APIRoute
31
32
  from fastapi.utils import generate_unique_id
32
- from strawberry.asgi import ASGIRequestAdapter, ASGIWebSocketAdapter
33
+ from strawberry.asgi import ASGIWebSocketAdapter
33
34
  from strawberry.exceptions import InvalidCustomContext
34
35
  from strawberry.fastapi.context import BaseContext, CustomContext
35
36
  from strawberry.http.async_base_view import AsyncBaseHTTPView
36
- from strawberry.http.exceptions import HTTPException
37
37
  from strawberry.http.typevars import Context, RootValue
38
38
  from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL
39
39
 
40
40
  if TYPE_CHECKING:
41
- from collections.abc import AsyncIterator, Awaitable, Sequence
41
+ from collections.abc import (
42
+ AsyncIterator,
43
+ Awaitable,
44
+ Sequence,
45
+ )
42
46
  from enum import Enum
43
47
 
44
48
  from starlette.routing import BaseRoute
@@ -57,7 +61,7 @@ class GraphQLRouter(
57
61
  APIRouter,
58
62
  ):
59
63
  allow_queries_via_get = True
60
- request_adapter_class = ASGIRequestAdapter
64
+ request_adapter_class = StarletteRequestAdapter
61
65
  websocket_adapter_class = ASGIWebSocketAdapter
62
66
 
63
67
  @staticmethod