Skip to content

add type conversion sqlalchemy_utils JSONType #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion graphene_sqlalchemy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
from .fields import SQLAlchemyConnectionField

try:
from sqlalchemy_utils import ChoiceType, ScalarListType
from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType
except ImportError:
class ChoiceType(object):
pass

class ScalarListType(object):
pass

class JSONType(object):
pass


def convert_sqlalchemy_relationship(relationship, registry):
direction = relationship.direction
Expand Down Expand Up @@ -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))
6 changes: 5 additions & 1 deletion graphene_sqlalchemy/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down