mirror of
https://github.com/graphql-python/graphene.git
synced 2024-12-04 07:23:59 +03:00
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
This commit is contained in:
parent
dca31dc61d
commit
cf97cbb1de
|
@ -1,5 +1,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from dateutil.parser import isoparse
|
||||||
|
|
||||||
from graphql.error import GraphQLError
|
from graphql.error import GraphQLError
|
||||||
from graphql.language import StringValueNode, print_ast
|
from graphql.language import StringValueNode, print_ast
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ class DateTime(Scalar):
|
||||||
f"DateTime cannot represent non-string value: {repr(value)}"
|
f"DateTime cannot represent non-string value: {repr(value)}"
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
return datetime.datetime.fromisoformat(value)
|
return isoparse(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise GraphQLError(f"DateTime cannot represent value: {repr(value)}")
|
raise GraphQLError(f"DateTime cannot represent value: {repr(value)}")
|
||||||
|
|
||||||
|
|
|
@ -227,6 +227,18 @@ def test_time_query_variable(sample_time):
|
||||||
assert result.data == {"time": isoformat}
|
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(sample_date, sample_datetime, sample_time):
|
||||||
def _test_bad_variables(type_, input_):
|
def _test_bad_variables(type_, input_):
|
||||||
result = schema.execute(
|
result = schema.execute(
|
||||||
|
|
7
setup.py
7
setup.py
|
@ -53,7 +53,11 @@ tests_require = [
|
||||||
"coveralls>=3.3,<5",
|
"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(
|
setup(
|
||||||
name="graphene",
|
name="graphene",
|
||||||
|
@ -83,6 +87,7 @@ setup(
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"graphql-core>=3.1,<3.3",
|
"graphql-core>=3.1,<3.3",
|
||||||
"graphql-relay>=3.1,<3.3",
|
"graphql-relay>=3.1,<3.3",
|
||||||
|
"python-dateutil>=2.7.0,<3",
|
||||||
"typing-extensions>=4.7.1,<5",
|
"typing-extensions>=4.7.1,<5",
|
||||||
],
|
],
|
||||||
tests_require=tests_require,
|
tests_require=tests_require,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user