diff --git a/graphene_sqlalchemy/converter.py b/graphene_sqlalchemy/converter.py index f4b805e2..18842fb0 100644 --- a/graphene_sqlalchemy/converter.py +++ b/graphene_sqlalchemy/converter.py @@ -16,10 +16,21 @@ from .registry import get_global_registry from .resolvers import get_attr_resolver, get_custom_resolver + +class DummyImport: + def __getattr__(self, name): + return object + + +try: + import sqlalchemy_utils +except ImportError: + sqlalchemy_utils = DummyImport() + try: - from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType, TSVectorType + from geoalchemy2.elements import Geometry except ImportError: - ChoiceType = JSONType = ScalarListType = TSVectorType = object + Geometry = object is_selectin_available = getattr(strategies, 'SelectInLoader', None) @@ -183,7 +194,12 @@ def convert_sqlalchemy_type(type, column, registry=None): @convert_sqlalchemy_type.register(postgresql.UUID) @convert_sqlalchemy_type.register(postgresql.INET) @convert_sqlalchemy_type.register(postgresql.CIDR) -@convert_sqlalchemy_type.register(TSVectorType) +@convert_sqlalchemy_type.register(sqlalchemy_utils.TSVectorType) +@convert_sqlalchemy_type.register(sqlalchemy_utils.UUIDType) +@convert_sqlalchemy_type.register(sqlalchemy_utils.EmailType) +@convert_sqlalchemy_type.register(sqlalchemy_utils.URLType) +@convert_sqlalchemy_type.register(sqlalchemy_utils.IPAddressType) +@convert_sqlalchemy_type.register(Geometry) def convert_column_to_string(type, column, registry=None): return String @@ -218,7 +234,7 @@ def convert_enum_to_enum(type, column, registry=None): # TODO Make ChoiceType conversion consistent with other enums -@convert_sqlalchemy_type.register(ChoiceType) +@convert_sqlalchemy_type.register(sqlalchemy_utils.ChoiceType) def convert_choice_to_enum(type, column, registry=None): name = "{}_{}".format(column.table.name, column.name).upper() if isinstance(type.choices, EnumMeta): @@ -229,7 +245,7 @@ def convert_choice_to_enum(type, column, registry=None): return Enum(name, type.choices) -@convert_sqlalchemy_type.register(ScalarListType) +@convert_sqlalchemy_type.register(sqlalchemy_utils.ScalarListType) def convert_scalar_list_to_list(type, column, registry=None): return List(String) @@ -248,6 +264,6 @@ def convert_json_to_string(type, column, registry=None): return JSONString -@convert_sqlalchemy_type.register(JSONType) +@convert_sqlalchemy_type.register(sqlalchemy_utils.JSONType) def convert_json_type_to_string(type, column, registry=None): return JSONString diff --git a/graphene_sqlalchemy/tests/test_converter.py b/graphene_sqlalchemy/tests/test_converter.py index f0fc1802..d1f89a4d 100644 --- a/graphene_sqlalchemy/tests/test_converter.py +++ b/graphene_sqlalchemy/tests/test_converter.py @@ -13,7 +13,7 @@ from graphene.types.datetime import DateTime from graphene.types.json import JSONString -from ..converter import (convert_sqlalchemy_column, +from ..converter import (DummyImport, convert_sqlalchemy_column, convert_sqlalchemy_composite, convert_sqlalchemy_relationship) from ..fields import (UnsortedSQLAlchemyConnectionField, @@ -369,3 +369,9 @@ def __init__(self, col1, col2): Registry(), mock_resolver, ) + + +def test_dummy_import(): + """The dummy module returns 'object' for a query for any member""" + dummy_module = DummyImport() + assert dummy_module.foo == object