mirror of
https://github.com/graphql-python/graphene.git
synced 2024-12-01 14:03:58 +03:00
parent
966aba06cd
commit
47c63f3dd7
|
@ -25,7 +25,7 @@ class Date(Scalar):
|
||||||
return date.isoformat()
|
return date.isoformat()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_literal(cls, node):
|
def parse_literal(cls, node, _variables=None):
|
||||||
if not isinstance(node, StringValueNode):
|
if not isinstance(node, StringValueNode):
|
||||||
raise GraphQLError(
|
raise GraphQLError(
|
||||||
f"Date cannot represent non-string value: {print_ast(node)}"
|
f"Date cannot represent non-string value: {print_ast(node)}"
|
||||||
|
@ -58,7 +58,7 @@ class DateTime(Scalar):
|
||||||
return dt.isoformat()
|
return dt.isoformat()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_literal(cls, node):
|
def parse_literal(cls, node, _variables=None):
|
||||||
if not isinstance(node, StringValueNode):
|
if not isinstance(node, StringValueNode):
|
||||||
raise GraphQLError(
|
raise GraphQLError(
|
||||||
f"DateTime cannot represent non-string value: {print_ast(node)}"
|
f"DateTime cannot represent non-string value: {print_ast(node)}"
|
||||||
|
@ -93,7 +93,7 @@ class Time(Scalar):
|
||||||
return time.isoformat()
|
return time.isoformat()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_literal(cls, node):
|
def parse_literal(cls, node, _variables=None):
|
||||||
if not isinstance(node, StringValueNode):
|
if not isinstance(node, StringValueNode):
|
||||||
raise GraphQLError(
|
raise GraphQLError(
|
||||||
f"Time cannot represent non-string value: {print_ast(node)}"
|
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}
|
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):
|
def test_date_query(sample_date):
|
||||||
isoformat = sample_date.isoformat()
|
isoformat = sample_date.isoformat()
|
||||||
|
|
||||||
|
@ -68,6 +85,23 @@ def test_date_query(sample_date):
|
||||||
assert result.data == {"date": isoformat}
|
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):
|
def test_time_query(sample_time):
|
||||||
isoformat = sample_time.isoformat()
|
isoformat = sample_time.isoformat()
|
||||||
|
|
||||||
|
@ -76,6 +110,23 @@ def test_time_query(sample_time):
|
||||||
assert result.data == {"time": isoformat}
|
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():
|
def test_bad_datetime_query():
|
||||||
not_a_date = "Some string that's not a datetime"
|
not_a_date = "Some string that's not a datetime"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user