Skip to content

Commit

Permalink
BREAKING: Date&Time now convert to their corresponding graphene scala…
Browse files Browse the repository at this point in the history
…rs instead of String.

Signed-off-by: Erik Wrede <erikwrede2@gmail.com>
  • Loading branch information
erikwrede committed Jun 9, 2022
1 parent 1e17512 commit a6e6b8e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
15 changes: 13 additions & 2 deletions graphene_sqlalchemy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ def convert_sqlalchemy_type(type, column, registry=None):
)


@convert_sqlalchemy_type.register(types.Date)
@convert_sqlalchemy_type.register(types.Time)
@convert_sqlalchemy_type.register(types.String)
@convert_sqlalchemy_type.register(types.Text)
@convert_sqlalchemy_type.register(types.Unicode)
Expand All @@ -215,6 +213,18 @@ def convert_column_to_datetime(type, column, registry=None):
return DateTime


@convert_sqlalchemy_type.register(types.Time)
def convert_column_to_datetime(type, column, registry=None):
from graphene.types.datetime import Time
return Time


@convert_sqlalchemy_type.register(types.Date)
def convert_column_to_datetime(type, column, registry=None):
from graphene.types.datetime import Date
return Date


@convert_sqlalchemy_type.register(types.SmallInteger)
@convert_sqlalchemy_type.register(types.Integer)
def convert_column_to_int_or_id(type, column, registry=None):
Expand Down Expand Up @@ -283,6 +293,7 @@ def convert_json_type_to_string(type, column, registry=None):
def convert_variant_to_impl_type(type, column, registry=None):
return convert_sqlalchemy_type(type.impl, column, registry=registry)


@singledispatchbymatchfunction
def convert_sqlalchemy_hybrid_property_type(arg: Any):
existing_graphql_type = get_global_registry().get_type_for_model(arg)
Expand Down
13 changes: 6 additions & 7 deletions graphene_sqlalchemy/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ def test_should_unknown_sqlalchemy_field_raise_exception():
get_field(getattr(types, 'LargeBinary', types.BINARY)())


def test_should_date_convert_string():
assert get_field(types.Date()).type == graphene.String
def test_should_datetime_convert_datetime():
assert get_field(types.DateTime()).type == graphene.DateTime


def test_should_datetime_convert_datetime():
assert get_field(types.DateTime()).type == DateTime
def test_should_time_convert_time():
assert get_field(types.Time()).type == graphene.Time


def test_should_time_convert_string():
assert get_field(types.Time()).type == graphene.String
def test_should_date_convert_date():
assert get_field(types.Date()).type == graphene.Date


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



def test_should_manytomany_convert_connectionorlist():
class A(SQLAlchemyObjectType):
class Meta:
Expand Down

0 comments on commit a6e6b8e

Please sign in to comment.