Skip to content

Commit

Permalink
fix: use dateutil-parse for < 3.11 support (#1581)
Browse files Browse the repository at this point in the history
* fix: use dateutil-parse for < 3.11 support

* chore: lint

* chore: lint

* fix mypy deps

* fix mypy deps

* chore: lint

* chore: fix test
  • Loading branch information
erikwrede authored Oct 27, 2024
1 parent dca31dc commit cf97cbb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
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
12 changes: 12 additions & 0 deletions graphene/types/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ def test_time_query_variable(sample_time):
assert result.data == {"time": isoformat}


def test_support_isoformat():
isoformat = "2011-11-04T00:05:23Z"

# test time variable provided as Python time
result = schema.execute(
"""query DateTime($time: DateTime){ datetime(in: $time) }""",
variables={"time": isoformat},
)
assert not result.errors
assert result.data == {"datetime": "2011-11-04T00:05:23+00:00"}


def test_bad_variables(sample_date, sample_datetime, sample_time):
def _test_bad_variables(type_, input_):
result = schema.execute(
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ def run_tests(self):
"coveralls>=3.3,<5",
]

dev_requires = ["ruff==0.5.0"] + tests_require
dev_requires = [
"ruff==0.5.0",
"types-python-dateutil>=2.8.1,<3",
"mypy>=1.10,<2",
] + tests_require

setup(
name="graphene",
Expand Down Expand Up @@ -83,6 +87,7 @@ def run_tests(self):
install_requires=[
"graphql-core>=3.1,<3.3",
"graphql-relay>=3.1,<3.3",
"python-dateutil>=2.7.0,<3",
"typing-extensions>=4.7.1,<5",
],
tests_require=tests_require,
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ commands =
[testenv:mypy]
basepython = python3.10
deps =
mypy>=1.10,<2
.[dev]
commands =
mypy graphene

Expand Down

0 comments on commit cf97cbb

Please sign in to comment.