mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-25 02:53:54 +03:00
fix: use dateutil-parse for < 3.11 support
This commit is contained in:
parent
dca31dc61d
commit
c9a4d5301c
|
@ -1,5 +1,7 @@
|
|||
import datetime
|
||||
|
||||
from dateutil.parser import isoparse
|
||||
|
||||
from graphql.error import GraphQLError
|
||||
from graphql.language import StringValueNode, print_ast
|
||||
|
||||
|
@ -71,7 +73,7 @@ class DateTime(Scalar):
|
|||
f"DateTime cannot represent non-string value: {repr(value)}"
|
||||
)
|
||||
try:
|
||||
return datetime.datetime.fromisoformat(value)
|
||||
return isoparse(value)
|
||||
except ValueError:
|
||||
raise GraphQLError(f"DateTime cannot represent value: {repr(value)}")
|
||||
|
||||
|
|
|
@ -226,6 +226,23 @@ def test_time_query_variable(sample_time):
|
|||
assert not result.errors
|
||||
assert result.data == {"time": isoformat}
|
||||
|
||||
def test_support_isoformat():
|
||||
isoformat = 20111104
|
||||
|
||||
# test time variable provided as Python time
|
||||
result = schema.execute(
|
||||
"""query Test($time: Time){ time(at: $time) }""",
|
||||
variables={"time": sample_time},
|
||||
)
|
||||
assert not result.errors
|
||||
assert result.data == {"time": isoformat}
|
||||
|
||||
# test time variable in string representation
|
||||
result = schema.execute(
|
||||
"""query Test($time: Time){ time(at: $time) }""", variables={"time": isoformat}
|
||||
)
|
||||
assert not result.errors
|
||||
assert result.data == {"time": isoformat}
|
||||
|
||||
def test_bad_variables(sample_date, sample_datetime, sample_time):
|
||||
def _test_bad_variables(type_, input_):
|
||||
|
|
Loading…
Reference in New Issue
Block a user