Skip to content

Commit 47c63f3

Browse files
authored
Fix DateTime Scalar parse_literal methods (#1199) (#1200)
1 parent 966aba0 commit 47c63f3

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

graphene/types/datetime.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def serialize(date):
2525
return date.isoformat()
2626

2727
@classmethod
28-
def parse_literal(cls, node):
28+
def parse_literal(cls, node, _variables=None):
2929
if not isinstance(node, StringValueNode):
3030
raise GraphQLError(
3131
f"Date cannot represent non-string value: {print_ast(node)}"
@@ -58,7 +58,7 @@ def serialize(dt):
5858
return dt.isoformat()
5959

6060
@classmethod
61-
def parse_literal(cls, node):
61+
def parse_literal(cls, node, _variables=None):
6262
if not isinstance(node, StringValueNode):
6363
raise GraphQLError(
6464
f"DateTime cannot represent non-string value: {print_ast(node)}"
@@ -93,7 +93,7 @@ def serialize(time):
9393
return time.isoformat()
9494

9595
@classmethod
96-
def parse_literal(cls, node):
96+
def parse_literal(cls, node, _variables=None):
9797
if not isinstance(node, StringValueNode):
9898
raise GraphQLError(
9999
f"Time cannot represent non-string value: {print_ast(node)}"

graphene/types/tests/test_datetime.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ def test_datetime_query(sample_datetime):
6060
assert result.data == {"datetime": isoformat}
6161

6262

63+
def test_datetime_query_with_variables(sample_datetime):
64+
isoformat = sample_datetime.isoformat()
65+
66+
result = schema.execute(
67+
"""
68+
query GetDate($datetime: DateTime) {
69+
literal: datetime(in: "%s")
70+
value: datetime(in: $datetime)
71+
}
72+
"""
73+
% isoformat,
74+
variable_values={"datetime": isoformat},
75+
)
76+
assert not result.errors
77+
assert result.data == {"literal": isoformat, "value": isoformat}
78+
79+
6380
def test_date_query(sample_date):
6481
isoformat = sample_date.isoformat()
6582

@@ -68,6 +85,23 @@ def test_date_query(sample_date):
6885
assert result.data == {"date": isoformat}
6986

7087

88+
def test_date_query_with_variables(sample_date):
89+
isoformat = sample_date.isoformat()
90+
91+
result = schema.execute(
92+
"""
93+
query GetDate($date: Date) {
94+
literal: date(in: "%s")
95+
value: date(in: $date)
96+
}
97+
"""
98+
% isoformat,
99+
variable_values={"date": isoformat},
100+
)
101+
assert not result.errors
102+
assert result.data == {"literal": isoformat, "value": isoformat}
103+
104+
71105
def test_time_query(sample_time):
72106
isoformat = sample_time.isoformat()
73107

@@ -76,6 +110,23 @@ def test_time_query(sample_time):
76110
assert result.data == {"time": isoformat}
77111

78112

113+
def test_time_query_with_variables(sample_time):
114+
isoformat = sample_time.isoformat()
115+
116+
result = schema.execute(
117+
"""
118+
query GetTime($time: Time) {
119+
literal: time(at: "%s")
120+
value: time(at: $time)
121+
}
122+
"""
123+
% isoformat,
124+
variable_values={"time": isoformat},
125+
)
126+
assert not result.errors
127+
assert result.data == {"literal": isoformat, "value": isoformat}
128+
129+
79130
def test_bad_datetime_query():
80131
not_a_date = "Some string that's not a datetime"
81132

0 commit comments

Comments
 (0)