Skip to content

Commit d4d1acc

Browse files
committed
add type conversion sqlalchemy_utils JSONType
1 parent c69017e commit d4d1acc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

graphene_sqlalchemy/converter.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
from .fields import SQLAlchemyConnectionField
1212

1313
try:
14-
from sqlalchemy_utils import ChoiceType, ScalarListType
14+
from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType
1515
except ImportError:
1616
class ChoiceType(object):
1717
pass
1818

1919
class ScalarListType(object):
2020
pass
2121

22+
class JSONType(object):
23+
pass
24+
2225

2326
def convert_sqlalchemy_relationship(relationship, registry):
2427
direction = relationship.direction
@@ -133,3 +136,8 @@ def convert_postgres_array_to_list(type, column, registry=None):
133136
@convert_sqlalchemy_type.register(postgresql.JSONB)
134137
def convert_json_to_string(type, column, registry=None):
135138
return JSONString(description=column.doc, required=not(column.nullable))
139+
140+
141+
@convert_sqlalchemy_type.register(JSONType)
142+
def convert_json_type_to_string(type, column, registry=None):
143+
return JSONString(description=column.doc, required=not(column.nullable))

graphene_sqlalchemy/tests/test_converter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sqlalchemy.dialects import postgresql
44
from sqlalchemy.ext.declarative import declarative_base
55
from sqlalchemy.orm import composite
6-
from sqlalchemy_utils import ChoiceType, ScalarListType
6+
from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType
77

88
import graphene
99
from graphene.relay import Node
@@ -127,6 +127,10 @@ def test_should_scalar_list_convert_list():
127127
assert_column_conversion(ScalarListType(), graphene.List)
128128

129129

130+
def test_should_jsontype_convert_jsonstring():
131+
assert_column_conversion(JSONType(), JSONString)
132+
133+
130134
def test_should_manytomany_convert_connectionorlist():
131135
registry = Registry()
132136
dynamic_field = convert_sqlalchemy_relationship(Reporter.pets.property, registry)

0 commit comments

Comments
 (0)