Skip to content

Commit a6e6b8e

Browse files
committed
BREAKING: Date&Time now convert to their corresponding graphene scalars instead of String.
Signed-off-by: Erik Wrede <[email protected]>
1 parent 1e17512 commit a6e6b8e

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

graphene_sqlalchemy/converter.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ def convert_sqlalchemy_type(type, column, registry=None):
195195
)
196196

197197

198-
@convert_sqlalchemy_type.register(types.Date)
199-
@convert_sqlalchemy_type.register(types.Time)
200198
@convert_sqlalchemy_type.register(types.String)
201199
@convert_sqlalchemy_type.register(types.Text)
202200
@convert_sqlalchemy_type.register(types.Unicode)
@@ -215,6 +213,18 @@ def convert_column_to_datetime(type, column, registry=None):
215213
return DateTime
216214

217215

216+
@convert_sqlalchemy_type.register(types.Time)
217+
def convert_column_to_datetime(type, column, registry=None):
218+
from graphene.types.datetime import Time
219+
return Time
220+
221+
222+
@convert_sqlalchemy_type.register(types.Date)
223+
def convert_column_to_datetime(type, column, registry=None):
224+
from graphene.types.datetime import Date
225+
return Date
226+
227+
218228
@convert_sqlalchemy_type.register(types.SmallInteger)
219229
@convert_sqlalchemy_type.register(types.Integer)
220230
def convert_column_to_int_or_id(type, column, registry=None):
@@ -283,6 +293,7 @@ def convert_json_type_to_string(type, column, registry=None):
283293
def convert_variant_to_impl_type(type, column, registry=None):
284294
return convert_sqlalchemy_type(type.impl, column, registry=registry)
285295

296+
286297
@singledispatchbymatchfunction
287298
def convert_sqlalchemy_hybrid_property_type(arg: Any):
288299
existing_graphql_type = get_global_registry().get_type_for_model(arg)

graphene_sqlalchemy/tests/test_converter.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ def test_should_unknown_sqlalchemy_field_raise_exception():
5858
get_field(getattr(types, 'LargeBinary', types.BINARY)())
5959

6060

61-
def test_should_date_convert_string():
62-
assert get_field(types.Date()).type == graphene.String
61+
def test_should_datetime_convert_datetime():
62+
assert get_field(types.DateTime()).type == graphene.DateTime
6363

6464

65-
def test_should_datetime_convert_datetime():
66-
assert get_field(types.DateTime()).type == DateTime
65+
def test_should_time_convert_time():
66+
assert get_field(types.Time()).type == graphene.Time
6767

6868

69-
def test_should_time_convert_string():
70-
assert get_field(types.Time()).type == graphene.String
69+
def test_should_date_convert_date():
70+
assert get_field(types.Date()).type == graphene.Date
7171

7272

7373
def test_should_string_convert_string():
@@ -203,7 +203,6 @@ def test_should_variant_string_convert_string():
203203
assert get_field(types.Variant(types.String(), {})).type == graphene.String
204204

205205

206-
207206
def test_should_manytomany_convert_connectionorlist():
208207
class A(SQLAlchemyObjectType):
209208
class Meta:

0 commit comments

Comments
 (0)