Skip to content

Commit

Permalink
Override encode_json() method in Django BaseView to use DjangoJSONEnc…
Browse files Browse the repository at this point in the history
…oder (#3273)

Signed-off-by: Noam Stolero <noamstolero@gmail.com>
  • Loading branch information
Noam Stolero authored Dec 6, 2023
1 parent 3c7b57d commit 75cb9ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 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: minor

Override encode_json() method in Django BaseView to use DjangoJSONEncoder
7 changes: 5 additions & 2 deletions strawberry/django/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)

from asgiref.sync import markcoroutinefunction
from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpRequest, HttpResponseNotAllowed, JsonResponse
from django.http.response import HttpResponse
from django.template import RequestContext, Template
Expand Down Expand Up @@ -159,8 +160,7 @@ def __init__(
def create_response(
self, response_data: GraphQLHTTPResponse, sub_response: HttpResponse
) -> HttpResponse:
data = self.encode_json(response_data) # type: ignore

data = self.encode_json(response_data)
response = HttpResponse(
data,
content_type="application/json",
Expand All @@ -177,6 +177,9 @@ def create_response(

return response

def encode_json(self, response_data: GraphQLHTTPResponse) -> str:
return json.dumps(response_data, cls=DjangoJSONEncoder)


class GraphQLView(
BaseView,
Expand Down

0 comments on commit 75cb9ec

Please sign in to comment.