Skip to content

Commit

Permalink
BREAKING: PG UUID & sqlalchemy_utils.UUIDType now convert to graphene…
Browse files Browse the repository at this point in the history
….UUID instead of graphene.String

Signed-off-by: Erik Wrede <erikwrede2@gmail.com>
  • Loading branch information
erikwrede committed Jun 9, 2022
1 parent 5b86145 commit 2a89227
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 10 additions & 8 deletions graphene_sqlalchemy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from sqlalchemy.dialects import postgresql
from sqlalchemy.orm import interfaces, strategies

from graphene import (ID, Boolean, Date, DateTime, Dynamic, Enum, Field, Float,
Int, List, String, Time)
from graphene import (ID, Boolean, Date, Time, DateTime, Dynamic, Enum, Field, Float,
Int, List, String, Time, UUID)
from graphene.types.json import JSONString

from .batching import get_batch_resolver
Expand All @@ -30,9 +30,9 @@

try:
from sqlalchemy_utils import (ChoiceType, JSONType, ScalarListType,
TSVectorType)
TSVectorType, UUIDType)
except ImportError:
ChoiceType = JSONType = ScalarListType = TSVectorType = object
ChoiceType = JSONType = ScalarListType = TSVectorType = UUIDType = object

try:
from sqlalchemy_utils.types.choice import EnumTypeImpl
Expand Down Expand Up @@ -199,29 +199,31 @@ def convert_sqlalchemy_type(type, column, registry=None):
@convert_sqlalchemy_type.register(types.Text)
@convert_sqlalchemy_type.register(types.Unicode)
@convert_sqlalchemy_type.register(types.UnicodeText)
@convert_sqlalchemy_type.register(postgresql.UUID)
@convert_sqlalchemy_type.register(postgresql.INET)
@convert_sqlalchemy_type.register(postgresql.CIDR)
@convert_sqlalchemy_type.register(TSVectorType)
def convert_column_to_string(type, column, registry=None):
return String


@convert_sqlalchemy_type.register(postgresql.UUID)
@convert_sqlalchemy_type.register(UUIDType)
def convert_column_to_uuid(type, column, registry=None):
return UUID


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


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


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


Expand Down
8 changes: 6 additions & 2 deletions graphene_sqlalchemy/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.inspection import inspect
from sqlalchemy.orm import column_property, composite
from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType
from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType, UUIDType

import graphene
from graphene import Boolean, Float, Int, Scalar, String
Expand Down Expand Up @@ -300,7 +300,11 @@ class Meta:


def test_should_postgresql_uuid_convert():
assert get_field(postgresql.UUID()).type == graphene.String
assert get_field(postgresql.UUID()).type == graphene.UUID


def test_should_sqlalchemy_utils_uuid_convert():
assert get_field(UUIDType()).type == graphene.UUID


def test_should_postgresql_enum_convert():
Expand Down

0 comments on commit 2a89227

Please sign in to comment.