From da41c060413bce425c7a13db57ee76e6cc60844d Mon Sep 17 00:00:00 2001 From: Simon Hewitt Date: Mon, 19 Sep 2016 13:25:26 -0700 Subject: [PATCH] add type conversion sqlalchemy_utils JSONType --- graphene_sqlalchemy/converter.py | 10 +++++++++- graphene_sqlalchemy/tests/test_converter.py | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/graphene_sqlalchemy/converter.py b/graphene_sqlalchemy/converter.py index 15ed761b..05690697 100644 --- a/graphene_sqlalchemy/converter.py +++ b/graphene_sqlalchemy/converter.py @@ -11,7 +11,7 @@ from .fields import SQLAlchemyConnectionField try: - from sqlalchemy_utils import ChoiceType, ScalarListType + from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType except ImportError: class ChoiceType(object): pass @@ -19,6 +19,9 @@ class ChoiceType(object): class ScalarListType(object): pass + class JSONType(object): + pass + def convert_sqlalchemy_relationship(relationship, registry): direction = relationship.direction @@ -134,3 +137,8 @@ def convert_postgres_array_to_list(type, column, registry=None): @convert_sqlalchemy_type.register(postgresql.JSONB) def convert_json_to_string(type, column, registry=None): return JSONString(description=column.doc, required=not(column.nullable)) + + +@convert_sqlalchemy_type.register(JSONType) +def convert_json_type_to_string(type, column, registry=None): + return JSONString(description=column.doc, required=not(column.nullable)) diff --git a/graphene_sqlalchemy/tests/test_converter.py b/graphene_sqlalchemy/tests/test_converter.py index 4eb26b4e..0157f837 100644 --- a/graphene_sqlalchemy/tests/test_converter.py +++ b/graphene_sqlalchemy/tests/test_converter.py @@ -4,7 +4,7 @@ from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import composite from sqlalchemy.sql.elements import Label -from sqlalchemy_utils import ChoiceType, ScalarListType +from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType import graphene from graphene.relay import Node @@ -134,6 +134,10 @@ def test_should_scalar_list_convert_list(): assert_column_conversion(ScalarListType(), graphene.List) +def test_should_jsontype_convert_jsonstring(): + assert_column_conversion(JSONType(), JSONString) + + def test_should_manytomany_convert_connectionorlist(): registry = Registry() dynamic_field = convert_sqlalchemy_relationship(Reporter.pets.property, registry)