Skip to content

Commit

Permalink
change: parse query params to use parse_json (#3272)
Browse files Browse the repository at this point in the history
* change: parse query to use parse_json

* docs: release file

* fix: extraneous typing
  • Loading branch information
thearchitector authored Dec 6, 2023
1 parent f0332fc commit fdb87ec
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Release type: patch

Fixed the base view so it uses `parse_json` when loading parameters from the query string instead of `json.loads`.
2 changes: 1 addition & 1 deletion strawberry/http/async_base_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ async def parse_http_body(

return GraphQLRequestData(
query=data.get("query"),
variables=data.get("variables"), # type: ignore
variables=data.get("variables"),
operation_name=data.get("operationName"),
)

Expand Down
4 changes: 2 additions & 2 deletions strawberry/http/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def should_render_graphql_ide(self, request: BaseRequestProtocol) -> bool:
def is_request_allowed(self, request: BaseRequestProtocol) -> bool:
return request.method in ("GET", "POST")

def parse_json(self, data: Union[str, bytes]) -> Dict[str, str]:
def parse_json(self, data: Union[str, bytes]) -> Any:
try:
return json.loads(data)
except json.JSONDecodeError as e:
Expand All @@ -65,7 +65,7 @@ def parse_query_params(
variables = variables[0]

if variables:
params["variables"] = json.loads(variables)
params["variables"] = self.parse_json(variables)

return params

Expand Down
2 changes: 1 addition & 1 deletion strawberry/http/sync_base_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def parse_http_body(self, request: SyncHTTPRequestAdapter) -> GraphQLRequestData

return GraphQLRequestData(
query=data.get("query"),
variables=data.get("variables"), # type: ignore
variables=data.get("variables"),
operation_name=data.get("operationName"),
)

Expand Down

0 comments on commit fdb87ec

Please sign in to comment.