Skip to content

Commit 2b3efe8

Browse files
committed
Add release notes
1 parent aff2111 commit 2b3efe8

12 files changed

Lines changed: 90 additions & 51 deletions

File tree

RELEASE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Release type: patch
2+
3+
This release removes some internal code in favour of using an external dependency,
4+
this will help us with maintaining the codebase in the future 😊

strawberry/aiohttp/views.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
from strawberry.schema import BaseSchema
4040

4141

42-
# Aiohttp adapter is now imported from lia
43-
44-
4542
class AiohttpWebSocketAdapter(AsyncWebSocketAdapter):
4643
def __init__(
4744
self, view: AsyncBaseHTTPView, request: web.Request, ws: web.WebSocketResponse

strawberry/asgi/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
)
1212
from typing_extensions import TypeGuard
1313

14-
from lia import HTTPException
15-
from lia import StarletteRequestAdapter as LiaStarletteRequestAdapter
14+
from lia import HTTPException, StarletteRequestAdapter
1615
from starlette import status
1716
from starlette.requests import Request
1817
from starlette.responses import (
@@ -48,10 +47,6 @@
4847
from strawberry.schema import BaseSchema
4948

5049

51-
# Use lia's StarletteRequestAdapter directly
52-
ASGIRequestAdapter = LiaStarletteRequestAdapter
53-
54-
5550
class ASGIWebSocketAdapter(AsyncWebSocketAdapter):
5651
def __init__(
5752
self, view: AsyncBaseHTTPView, request: WebSocket, response: WebSocket
@@ -97,7 +92,7 @@ class GraphQL(
9792
]
9893
):
9994
allow_queries_via_get = True
100-
request_adapter_class = ASGIRequestAdapter
95+
request_adapter_class = StarletteRequestAdapter
10196
websocket_adapter_class = ASGIWebSocketAdapter
10297

10398
def __init__(

strawberry/chalice/views.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
from strawberry.schema import BaseSchema
1818

1919

20-
# Chalice adapter is now imported from lia
21-
22-
2320
class GraphQLView(
2421
SyncBaseHTTPView[Request, Response, TemporalResponse, Context, RootValue]
2522
):

strawberry/channels/handlers/http_handler.py

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,35 @@ async def get_body(self) -> bytes:
133133
return self.request.body
134134

135135
async def get_form_data(self) -> FormData:
136-
return self.request.form_data
136+
form_data = self.request.form_data
137+
# Handle legacy case where form_data might be a dict
138+
if isinstance(form_data, dict):
139+
return FormData(
140+
files=form_data.get("files", {}), form=form_data.get("form", {})
141+
)
142+
return form_data
143+
144+
@property
145+
def url(self) -> str:
146+
scheme = self.request.consumer.scope["scheme"]
147+
host = self.headers.get("host", "localhost")
148+
path = self.request.consumer.scope["path"]
149+
query_string = self.request.consumer.scope["query_string"]
150+
url = f"{scheme}://{host}{path}"
151+
if query_string:
152+
url += f"?{query_string.decode()}"
153+
return url
154+
155+
@property
156+
def cookies(self) -> Mapping[str, str]:
157+
cookie_header = self.headers.get("cookie", "")
158+
cookies = {}
159+
if cookie_header:
160+
for cookie in cookie_header.split(";"):
161+
if "=" in cookie:
162+
key, value = cookie.split("=", 1)
163+
cookies[key.strip()] = value.strip()
164+
return cookies
137165

138166

139167
class SyncChannelsRequestAdapter(BaseChannelsRequestAdapter, SyncHTTPRequestAdapter):
@@ -143,11 +171,50 @@ def body(self) -> bytes:
143171

144172
@property
145173
def post_data(self) -> Mapping[str, Union[str, bytes]]:
146-
return self.request.form_data["form"]
174+
form_data = self.request.form_data
175+
# Handle legacy case where form_data might be a dict
176+
if isinstance(form_data, dict):
177+
return form_data.get("form", {})
178+
return form_data.form
147179

148180
@property
149181
def files(self) -> Mapping[str, Any]:
150-
return self.request.form_data["files"]
182+
form_data = self.request.form_data
183+
# Handle legacy case where form_data might be a dict
184+
if isinstance(form_data, dict):
185+
return form_data.get("files", {})
186+
return form_data.files
187+
188+
def get_form_data(self) -> FormData:
189+
form_data = self.request.form_data
190+
# Handle legacy case where form_data might be a dict
191+
if isinstance(form_data, dict):
192+
return FormData(
193+
files=form_data.get("files", {}), form=form_data.get("form", {})
194+
)
195+
return form_data
196+
197+
@property
198+
def url(self) -> str:
199+
scheme = self.request.consumer.scope["scheme"]
200+
host = self.headers.get("host", "localhost")
201+
path = self.request.consumer.scope["path"]
202+
query_string = self.request.consumer.scope["query_string"]
203+
url = f"{scheme}://{host}{path}"
204+
if query_string:
205+
url += f"?{query_string.decode()}"
206+
return url
207+
208+
@property
209+
def cookies(self) -> Mapping[str, str]:
210+
cookie_header = self.headers.get("cookie", "")
211+
cookies = {}
212+
if cookie_header:
213+
for cookie in cookie_header.split(";"):
214+
if "=" in cookie:
215+
key, value = cookie.split("=", 1)
216+
cookies[key.strip()] = value.strip()
217+
return cookies
151218

152219

153220
class BaseGraphQLHTTPConsumer(ChannelsConsumer, AsyncHttpConsumer):

strawberry/django/views.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ def __repr__(self) -> str:
6666
)
6767

6868

69-
# Django adapters are now imported from lia
70-
71-
7269
class BaseView:
7370
graphql_ide_html: str
7471

strawberry/flask/views.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
from strawberry.schema.base import BaseSchema
2626

2727

28-
# Flask adapters are now imported from lia
29-
30-
3128
class BaseGraphQLView:
3229
graphql_ide: Optional[GraphQL_IDE]
3330

@@ -95,9 +92,6 @@ def render_graphql_ide(self, request: Request) -> Response:
9592
return render_template_string(self.graphql_ide_html) # type: ignore
9693

9794

98-
# Async Flask adapter is now imported from lia
99-
100-
10195
class AsyncGraphQLView(
10296
BaseGraphQLView,
10397
AsyncBaseHTTPView[

strawberry/http/async_base_view.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
from typing_extensions import TypeGuard
1818

1919
from graphql import GraphQLError
20-
from lia import AsyncHTTPRequestAdapter as LiaAsyncHTTPRequestAdapter
21-
from lia import HTTPException
20+
from lia import AsyncHTTPRequestAdapter, HTTPException
2221

2322
from strawberry.exceptions import MissingQueryError
2423
from strawberry.file_uploads.utils import replace_placeholders_with_files
@@ -57,9 +56,6 @@
5756
WebSocketResponse,
5857
)
5958

60-
# Re-export the adapter from lia for backward compatibility
61-
AsyncHTTPRequestAdapter = LiaAsyncHTTPRequestAdapter
62-
6359

6460
class AsyncWebSocketAdapter(abc.ABC):
6561
def __init__(self, view: "AsyncBaseHTTPView") -> None:
@@ -96,7 +92,7 @@ class AsyncBaseHTTPView(
9692
keep_alive = False
9793
keep_alive_interval: Optional[float] = None
9894
connection_init_wait_timeout: timedelta = timedelta(minutes=1)
99-
request_adapter_class: Callable[[Request], LiaAsyncHTTPRequestAdapter]
95+
request_adapter_class: Callable[[Request], AsyncHTTPRequestAdapter]
10096
websocket_adapter_class: Callable[
10197
[
10298
"AsyncBaseHTTPView[Any, Any, Any, Any, Any, Context, RootValue]",
@@ -263,8 +259,15 @@ async def parse_multipart(self, request: AsyncHTTPRequestAdapter) -> dict[str, s
263259
except ValueError as e:
264260
raise HTTPException(400, "Unable to parse the multipart body") from e
265261

266-
operations = form_data["form"].get("operations", "{}")
267-
files_map = form_data["form"].get("map", "{}")
262+
# Handle legacy case where form_data might be a dict
263+
if isinstance(form_data, dict):
264+
operations = form_data.get("form", {}).get("operations", "{}")
265+
files_map = form_data.get("form", {}).get("map", "{}")
266+
files = form_data.get("files", {})
267+
else:
268+
operations = form_data.form.get("operations", "{}")
269+
files_map = form_data.form.get("map", "{}")
270+
files = form_data.files
268271

269272
if isinstance(operations, (bytes, str)):
270273
operations = self.parse_json(operations)
@@ -273,9 +276,7 @@ async def parse_multipart(self, request: AsyncHTTPRequestAdapter) -> dict[str, s
273276
files_map = self.parse_json(files_map)
274277

275278
try:
276-
return replace_placeholders_with_files(
277-
operations, files_map, form_data["files"]
278-
)
279+
return replace_placeholders_with_files(operations, files_map, files)
279280
except KeyError as e:
280281
raise HTTPException(400, "File(s) missing in form data") from e
281282

strawberry/http/sync_base_view.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
)
1010

1111
from graphql import GraphQLError
12-
from lia import HTTPException
13-
from lia import SyncHTTPRequestAdapter as LiaSyncHTTPRequestAdapter
12+
from lia import HTTPException, SyncHTTPRequestAdapter
1413

1514
from strawberry.exceptions import MissingQueryError
1615
from strawberry.file_uploads.utils import replace_placeholders_with_files
@@ -33,9 +32,6 @@
3332
from .parse_content_type import parse_content_type
3433
from .typevars import Context, Request, Response, RootValue, SubResponse
3534

36-
# Re-export the adapter from lia for backward compatibility
37-
SyncHTTPRequestAdapter = LiaSyncHTTPRequestAdapter
38-
3935

4036
class SyncBaseHTTPView(
4137
abc.ABC,
@@ -45,7 +41,7 @@ class SyncBaseHTTPView(
4541
schema: BaseSchema
4642
graphiql: Optional[bool]
4743
graphql_ide: Optional[GraphQL_IDE]
48-
request_adapter_class: Callable[[Request], LiaSyncHTTPRequestAdapter]
44+
request_adapter_class: Callable[[Request], SyncHTTPRequestAdapter]
4945

5046
# Methods that need to be implemented by individual frameworks
5147

strawberry/litestar/controller.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ class GraphQLResource(Struct):
151151
extensions: Optional[dict[str, object]]
152152

153153

154-
# Litestar adapter is now imported from lia
155-
156-
157154
class LitestarWebSocketAdapter(AsyncWebSocketAdapter):
158155
def __init__(
159156
self, view: AsyncBaseHTTPView, request: WebSocket, response: WebSocket

0 commit comments

Comments
 (0)