From 2f1bb7fc57d8d0d8ae2330e4dc7c640f283bf6b3 Mon Sep 17 00:00:00 2001 From: Viktor Pegy Date: Tue, 26 May 2020 13:29:07 +0300 Subject: [PATCH 1/2] upd (converter): add sqlalchemy.types.JSON handling --- graphene_sqlalchemy/converter.py | 1 + graphene_sqlalchemy/tests/test_converter.py | 1 + 2 files changed, 2 insertions(+) diff --git a/graphene_sqlalchemy/converter.py b/graphene_sqlalchemy/converter.py index f4b805e2..3de4d37c 100644 --- a/graphene_sqlalchemy/converter.py +++ b/graphene_sqlalchemy/converter.py @@ -249,5 +249,6 @@ def convert_json_to_string(type, column, registry=None): @convert_sqlalchemy_type.register(JSONType) +@convert_sqlalchemy_type.register(types.JSON) def convert_json_type_to_string(type, column, registry=None): return JSONString diff --git a/graphene_sqlalchemy/tests/test_converter.py b/graphene_sqlalchemy/tests/test_converter.py index f0fc1802..3d5d007e 100644 --- a/graphene_sqlalchemy/tests/test_converter.py +++ b/graphene_sqlalchemy/tests/test_converter.py @@ -188,6 +188,7 @@ def test_should_scalar_list_convert_list(): def test_should_jsontype_convert_jsonstring(): assert get_field(JSONType()).type == JSONString + assert get_field(types.JSON()).type == JSONString def test_should_manytomany_convert_connectionorlist(): From c150aa807e9dbef4652cf1dba9463b84598412a6 Mon Sep 17 00:00:00 2001 From: Viktor Pegy Date: Tue, 26 May 2020 13:41:50 +0300 Subject: [PATCH 2/2] upd (converter): add sqlalchemy.types.Variant handling --- graphene_sqlalchemy/converter.py | 5 +++++ graphene_sqlalchemy/tests/test_converter.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/graphene_sqlalchemy/converter.py b/graphene_sqlalchemy/converter.py index 3de4d37c..b632c2df 100644 --- a/graphene_sqlalchemy/converter.py +++ b/graphene_sqlalchemy/converter.py @@ -252,3 +252,8 @@ def convert_json_to_string(type, column, registry=None): @convert_sqlalchemy_type.register(types.JSON) def convert_json_type_to_string(type, column, registry=None): return JSONString + + +@convert_sqlalchemy_type.register(types.Variant) +def convert_variant_to_impl_type(type, column, registry=None): + return convert_sqlalchemy_type(type.impl, column, registry=registry) diff --git a/graphene_sqlalchemy/tests/test_converter.py b/graphene_sqlalchemy/tests/test_converter.py index 3d5d007e..617c3750 100644 --- a/graphene_sqlalchemy/tests/test_converter.py +++ b/graphene_sqlalchemy/tests/test_converter.py @@ -287,6 +287,14 @@ class Meta: assert graphene_type.type == A +def test_should_variant_int_convert_int(): + assert get_field(types.Variant(types.Integer(), {})).type == graphene.Int + + +def test_should_variant_string_convert_string(): + assert get_field(types.Variant(types.String(), {})).type == graphene.String + + def test_should_postgresql_uuid_convert(): assert get_field(postgresql.UUID()).type == graphene.String