mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-25 19:13:57 +03:00
parent
966aba06cd
commit
47c63f3dd7
|
@ -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)}"
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user