mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-04-16 15:12:06 +03:00
Fix 1075: serialize datetime value
This commit is contained in:
parent
558288afce
commit
7449efd2a3
|
@ -1,6 +1,7 @@
|
|||
import inspect
|
||||
import json
|
||||
import re
|
||||
import datetime
|
||||
|
||||
import six
|
||||
from django.db import connection, transaction
|
||||
|
@ -55,6 +56,11 @@ def instantiate_middleware(middlewares):
|
|||
yield middleware
|
||||
|
||||
|
||||
def stringify_datetime(value):
|
||||
if isinstance(value, datetime.datetime):
|
||||
return value.__str__()
|
||||
|
||||
|
||||
class GraphQLView(View):
|
||||
graphiql_template = "graphene/graphiql.html"
|
||||
|
||||
|
@ -240,9 +246,15 @@ class GraphQLView(View):
|
|||
|
||||
def json_encode(self, request, d, pretty=False):
|
||||
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):
|
||||
content_type = self.get_content_type(request)
|
||||
|
|
Loading…
Reference in New Issue
Block a user