Skip to content

Commit 4955043

Browse files
authored
Merge pull request #3 from sjhewitt/sqlautils-json
add type conversion sqlalchemy_utils JSONType
2 parents 802bc24 + da41c06 commit 4955043

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
@@ -134,3 +137,8 @@ def convert_postgres_array_to_list(type, column, registry=None):
134137
@convert_sqlalchemy_type.register(postgresql.JSONB)
135138
def convert_json_to_string(type, column, registry=None):
136139
return JSONString(description=column.doc, required=not(column.nullable))
140+
141+
142+
@convert_sqlalchemy_type.register(JSONType)
143+
def convert_json_type_to_string(type, column, registry=None):
144+
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
@@ -4,7 +4,7 @@
44
from sqlalchemy.ext.declarative import declarative_base
55
from sqlalchemy.orm import composite
66
from sqlalchemy.sql.elements import Label
7-
from sqlalchemy_utils import ChoiceType, ScalarListType
7+
from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType
88

99
import graphene
1010
from graphene.relay import Node
@@ -134,6 +134,10 @@ def test_should_scalar_list_convert_list():
134134
assert_column_conversion(ScalarListType(), graphene.List)
135135

136136

137+
def test_should_jsontype_convert_jsonstring():
138+
assert_column_conversion(JSONType(), JSONString)
139+
140+
137141
def test_should_manytomany_convert_connectionorlist():
138142
registry = Registry()
139143
dynamic_field = convert_sqlalchemy_relationship(Reporter.pets.property, registry)

0 commit comments

Comments
 (0)