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:
Anis Jonischkeit 2018-02-27 10:00:20 +10:00 committed by GitHub
parent 5df134e096
commit 84fbf5dc23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,8 +38,10 @@ class Date(Scalar):
@staticmethod @staticmethod
def parse_value(value): def parse_value(value):
return iso8601.parse_date(value).date() try:
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):
return iso8601.parse_date(value) try:
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):
dt = iso8601.parse_date('{}T{}'.format(cls.epoch_date, value)) try:
return datetime.time(dt.hour, dt.minute, dt.second, dt.microsecond, dt.tzinfo) dt = iso8601.parse_date('{}T{}'.format(cls.epoch_date, value))
return datetime.time(dt.hour, dt.minute, dt.second, dt.microsecond, dt.tzinfo)
except iso8601.ParseError:
return None