mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-11 16:52:25 +03:00
Fix 1075: serialize datetime value
This commit is contained in:
parent
558288afce
commit
7449efd2a3
|
@ -1,6 +1,7 @@
|
||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
import datetime
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from django.db import connection, transaction
|
from django.db import connection, transaction
|
||||||
|
@ -55,6 +56,11 @@ def instantiate_middleware(middlewares):
|
||||||
yield middleware
|
yield middleware
|
||||||
|
|
||||||
|
|
||||||
|
def stringify_datetime(value):
|
||||||
|
if isinstance(value, datetime.datetime):
|
||||||
|
return value.__str__()
|
||||||
|
|
||||||
|
|
||||||
class GraphQLView(View):
|
class GraphQLView(View):
|
||||||
graphiql_template = "graphene/graphiql.html"
|
graphiql_template = "graphene/graphiql.html"
|
||||||
|
|
||||||
|
@ -240,9 +246,15 @@ class GraphQLView(View):
|
||||||
|
|
||||||
def json_encode(self, request, d, pretty=False):
|
def json_encode(self, request, d, pretty=False):
|
||||||
if not (self.pretty or pretty) and not request.GET.get("pretty"):
|
if not (self.pretty or pretty) and not request.GET.get("pretty"):
|
||||||
return json.dumps(d, separators=(",", ":"))
|
return json.dumps(d, separators=(",", ":"), default=stringify_datetime)
|
||||||
|
|
||||||
return json.dumps(d, sort_keys=True, indent=2, separators=(",", ": "))
|
return json.dumps(
|
||||||
|
d,
|
||||||
|
sort_keys=True,
|
||||||
|
indent=2,
|
||||||
|
separators=(",", ": "),
|
||||||
|
default=stringify_datetime,
|
||||||
|
)
|
||||||
|
|
||||||
def parse_body(self, request):
|
def parse_body(self, request):
|
||||||
content_type = self.get_content_type(request)
|
content_type = self.get_content_type(request)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user