Skip to content

Commit

Permalink
fix: use dateutil-parse for < 3.11 support
Browse files Browse the repository at this point in the history
  • Loading branch information
erikwrede committed Oct 27, 2024
1 parent dca31dc commit c9a4d53
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion graphene/types/datetime.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime

from dateutil.parser import isoparse

from graphql.error import GraphQLError
from graphql.language import StringValueNode, print_ast

Expand Down Expand Up @@ -71,7 +73,7 @@ def parse_value(value):
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)}")

Expand Down
17 changes: 17 additions & 0 deletions graphene/types/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_):
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def run_tests(self):
"graphql-core>=3.1,<3.3",
"graphql-relay>=3.1,<3.3",
"typing-extensions>=4.7.1,<5",
"python-dateutil>=2.7.0,<3"
],
tests_require=tests_require,
extras_require={"test": tests_require, "dev": dev_requires},
Expand Down

0 comments on commit c9a4d53

Please sign in to comment.