mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Made DateTime types return GraphQLError on fail
This change makes it so that when an incorrectly formatted date string gets passed to a Date / Time argument a GraphQLError is returned rather than a GraphQLLocatedError. Since Date / Time are types, their errors should not be in the same class as errors in your application. This is also inline with how other types work in graphene (graphene.Int, graphene.Float)
This commit is contained in:
parent
5df134e096
commit
84fbf5dc23
|
@ -38,8 +38,10 @@ class Date(Scalar):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_value(value):
|
def parse_value(value):
|
||||||
|
try:
|
||||||
return iso8601.parse_date(value).date()
|
return iso8601.parse_date(value).date()
|
||||||
|
except iso8601.ParseError:
|
||||||
|
return None
|
||||||
|
|
||||||
class DateTime(Scalar):
|
class DateTime(Scalar):
|
||||||
'''
|
'''
|
||||||
|
@ -62,8 +64,10 @@ class DateTime(Scalar):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_value(value):
|
def parse_value(value):
|
||||||
|
try:
|
||||||
return iso8601.parse_date(value)
|
return iso8601.parse_date(value)
|
||||||
|
except iso8601.ParseError:
|
||||||
|
return None
|
||||||
|
|
||||||
class Time(Scalar):
|
class Time(Scalar):
|
||||||
'''
|
'''
|
||||||
|
@ -87,5 +91,8 @@ class Time(Scalar):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_value(cls, value):
|
def parse_value(cls, value):
|
||||||
|
try:
|
||||||
dt = iso8601.parse_date('{}T{}'.format(cls.epoch_date, value))
|
dt = iso8601.parse_date('{}T{}'.format(cls.epoch_date, value))
|
||||||
return datetime.time(dt.hour, dt.minute, dt.second, dt.microsecond, dt.tzinfo)
|
return datetime.time(dt.hour, dt.minute, dt.second, dt.microsecond, dt.tzinfo)
|
||||||
|
except iso8601.ParseError:
|
||||||
|
return None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user