Skip to content

Commit 2a89227

Browse files
committed
BREAKING: PG UUID & sqlalchemy_utils.UUIDType now convert to graphene.UUID instead of graphene.String
Signed-off-by: Erik Wrede <[email protected]>
1 parent 5b86145 commit 2a89227

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

graphene_sqlalchemy/converter.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from sqlalchemy.dialects import postgresql
1010
from sqlalchemy.orm import interfaces, strategies
1111

12-
from graphene import (ID, Boolean, Date, DateTime, Dynamic, Enum, Field, Float,
13-
Int, List, String, Time)
12+
from graphene import (ID, Boolean, Date, Time, DateTime, Dynamic, Enum, Field, Float,
13+
Int, List, String, Time, UUID)
1414
from graphene.types.json import JSONString
1515

1616
from .batching import get_batch_resolver
@@ -30,9 +30,9 @@
3030

3131
try:
3232
from sqlalchemy_utils import (ChoiceType, JSONType, ScalarListType,
33-
TSVectorType)
33+
TSVectorType, UUIDType)
3434
except ImportError:
35-
ChoiceType = JSONType = ScalarListType = TSVectorType = object
35+
ChoiceType = JSONType = ScalarListType = TSVectorType = UUIDType = object
3636

3737
try:
3838
from sqlalchemy_utils.types.choice import EnumTypeImpl
@@ -199,29 +199,31 @@ def convert_sqlalchemy_type(type, column, registry=None):
199199
@convert_sqlalchemy_type.register(types.Text)
200200
@convert_sqlalchemy_type.register(types.Unicode)
201201
@convert_sqlalchemy_type.register(types.UnicodeText)
202-
@convert_sqlalchemy_type.register(postgresql.UUID)
203202
@convert_sqlalchemy_type.register(postgresql.INET)
204203
@convert_sqlalchemy_type.register(postgresql.CIDR)
205204
@convert_sqlalchemy_type.register(TSVectorType)
206205
def convert_column_to_string(type, column, registry=None):
207206
return String
208207

209208

209+
@convert_sqlalchemy_type.register(postgresql.UUID)
210+
@convert_sqlalchemy_type.register(UUIDType)
211+
def convert_column_to_uuid(type, column, registry=None):
212+
return UUID
213+
214+
210215
@convert_sqlalchemy_type.register(types.DateTime)
211216
def convert_column_to_datetime(type, column, registry=None):
212-
from graphene.types.datetime import DateTime
213217
return DateTime
214218

215219

216220
@convert_sqlalchemy_type.register(types.Time)
217221
def convert_column_to_time(type, column, registry=None):
218-
from graphene.types.datetime import Time
219222
return Time
220223

221224

222225
@convert_sqlalchemy_type.register(types.Date)
223226
def convert_column_to_date(type, column, registry=None):
224-
from graphene.types.datetime import Date
225227
return Date
226228

227229

graphene_sqlalchemy/tests/test_converter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sqlalchemy.ext.declarative import declarative_base
88
from sqlalchemy.inspection import inspect
99
from sqlalchemy.orm import column_property, composite
10-
from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType
10+
from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType, UUIDType
1111

1212
import graphene
1313
from graphene import Boolean, Float, Int, Scalar, String
@@ -300,7 +300,11 @@ class Meta:
300300

301301

302302
def test_should_postgresql_uuid_convert():
303-
assert get_field(postgresql.UUID()).type == graphene.String
303+
assert get_field(postgresql.UUID()).type == graphene.UUID
304+
305+
306+
def test_should_sqlalchemy_utils_uuid_convert():
307+
assert get_field(UUIDType()).type == graphene.UUID
304308

305309

306310
def test_should_postgresql_enum_convert():

0 commit comments

Comments
 (0)