diff --git a/graphene/types/datetime.py b/graphene/types/datetime.py index 92234ba6..d4f74470 100644 --- a/graphene/types/datetime.py +++ b/graphene/types/datetime.py @@ -25,7 +25,7 @@ class Date(Scalar): return date.isoformat() @classmethod - def parse_literal(cls, node): + def parse_literal(cls, node, _variables=None): if not isinstance(node, StringValueNode): raise GraphQLError( f"Date cannot represent non-string value: {print_ast(node)}" @@ -58,7 +58,7 @@ class DateTime(Scalar): return dt.isoformat() @classmethod - def parse_literal(cls, node): + def parse_literal(cls, node, _variables=None): if not isinstance(node, StringValueNode): raise GraphQLError( f"DateTime cannot represent non-string value: {print_ast(node)}" @@ -93,7 +93,7 @@ class Time(Scalar): return time.isoformat() @classmethod - def parse_literal(cls, node): + def parse_literal(cls, node, _variables=None): if not isinstance(node, StringValueNode): raise GraphQLError( f"Time cannot represent non-string value: {print_ast(node)}" diff --git a/graphene/types/tests/test_datetime.py b/graphene/types/tests/test_datetime.py index 6a3241a1..74f88bd8 100644 --- a/graphene/types/tests/test_datetime.py +++ b/graphene/types/tests/test_datetime.py @@ -60,6 +60,23 @@ def test_datetime_query(sample_datetime): assert result.data == {"datetime": isoformat} +def test_datetime_query_with_variables(sample_datetime): + isoformat = sample_datetime.isoformat() + + result = schema.execute( + """ + query GetDate($datetime: DateTime) { + literal: datetime(in: "%s") + value: datetime(in: $datetime) + } + """ + % isoformat, + variable_values={"datetime": isoformat}, + ) + assert not result.errors + assert result.data == {"literal": isoformat, "value": isoformat} + + def test_date_query(sample_date): isoformat = sample_date.isoformat() @@ -68,6 +85,23 @@ def test_date_query(sample_date): assert result.data == {"date": isoformat} +def test_date_query_with_variables(sample_date): + isoformat = sample_date.isoformat() + + result = schema.execute( + """ + query GetDate($date: Date) { + literal: date(in: "%s") + value: date(in: $date) + } + """ + % isoformat, + variable_values={"date": isoformat}, + ) + assert not result.errors + assert result.data == {"literal": isoformat, "value": isoformat} + + def test_time_query(sample_time): isoformat = sample_time.isoformat() @@ -76,6 +110,23 @@ def test_time_query(sample_time): assert result.data == {"time": isoformat} +def test_time_query_with_variables(sample_time): + isoformat = sample_time.isoformat() + + result = schema.execute( + """ + query GetTime($time: Time) { + literal: time(at: "%s") + value: time(at: $time) + } + """ + % isoformat, + variable_values={"time": isoformat}, + ) + assert not result.errors + assert result.data == {"literal": isoformat, "value": isoformat} + + def test_bad_datetime_query(): not_a_date = "Some string that's not a datetime"