Skip to content

Commit cf97cbb

Browse files
authored
fix: use dateutil-parse for < 3.11 support (#1581)
* fix: use dateutil-parse for < 3.11 support * chore: lint * chore: lint * fix mypy deps * fix mypy deps * chore: lint * chore: fix test
1 parent dca31dc commit cf97cbb

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

graphene/types/datetime.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import datetime
22

3+
from dateutil.parser import isoparse
4+
35
from graphql.error import GraphQLError
46
from graphql.language import StringValueNode, print_ast
57

@@ -71,7 +73,7 @@ def parse_value(value):
7173
f"DateTime cannot represent non-string value: {repr(value)}"
7274
)
7375
try:
74-
return datetime.datetime.fromisoformat(value)
76+
return isoparse(value)
7577
except ValueError:
7678
raise GraphQLError(f"DateTime cannot represent value: {repr(value)}")
7779

graphene/types/tests/test_datetime.py

+12
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ def test_time_query_variable(sample_time):
227227
assert result.data == {"time": isoformat}
228228

229229

230+
def test_support_isoformat():
231+
isoformat = "2011-11-04T00:05:23Z"
232+
233+
# test time variable provided as Python time
234+
result = schema.execute(
235+
"""query DateTime($time: DateTime){ datetime(in: $time) }""",
236+
variables={"time": isoformat},
237+
)
238+
assert not result.errors
239+
assert result.data == {"datetime": "2011-11-04T00:05:23+00:00"}
240+
241+
230242
def test_bad_variables(sample_date, sample_datetime, sample_time):
231243
def _test_bad_variables(type_, input_):
232244
result = schema.execute(

setup.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ def run_tests(self):
5353
"coveralls>=3.3,<5",
5454
]
5555

56-
dev_requires = ["ruff==0.5.0"] + tests_require
56+
dev_requires = [
57+
"ruff==0.5.0",
58+
"types-python-dateutil>=2.8.1,<3",
59+
"mypy>=1.10,<2",
60+
] + tests_require
5761

5862
setup(
5963
name="graphene",
@@ -83,6 +87,7 @@ def run_tests(self):
8387
install_requires=[
8488
"graphql-core>=3.1,<3.3",
8589
"graphql-relay>=3.1,<3.3",
90+
"python-dateutil>=2.7.0,<3",
8691
"typing-extensions>=4.7.1,<5",
8792
],
8893
tests_require=tests_require,

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ commands =
2020
[testenv:mypy]
2121
basepython = python3.10
2222
deps =
23-
mypy>=1.10,<2
23+
.[dev]
2424
commands =
2525
mypy graphene
2626

0 commit comments

Comments
 (0)