Skip to content

Fix for issue graphql-python/graphene-sqlalchemy#288 #289

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
Apr 28, 2022
Merged
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
6 changes: 5 additions & 1 deletion graphene_sqlalchemy/converter.py
Original file line number Diff line number Diff line change
@@ -234,11 +234,15 @@ def convert_scalar_list_to_list(type, column, registry=None):
return List(String)


def init_array_list_recursive(inner_type, n):
return inner_type if n == 0 else List(init_array_list_recursive(inner_type, n-1))


@convert_sqlalchemy_type.register(types.ARRAY)
@convert_sqlalchemy_type.register(postgresql.ARRAY)
def convert_array_to_list(_type, column, registry=None):
inner_type = convert_sqlalchemy_type(column.type.item_type, column)
return List(inner_type)
return List(init_array_list_recursive(inner_type, (column.type.dimensions or 1) - 1))


@convert_sqlalchemy_type.register(postgresql.HSTORE)
15 changes: 15 additions & 0 deletions graphene_sqlalchemy/tests/test_converter.py
Original file line number Diff line number Diff line change
@@ -324,6 +324,21 @@ def test_should_array_convert():
assert field.type.of_type == graphene.Int


def test_should_2d_array_convert():
field = get_field(types.ARRAY(types.Integer, dimensions=2))
assert isinstance(field.type, graphene.List)
assert isinstance(field.type.of_type, graphene.List)
assert field.type.of_type.of_type == graphene.Int


def test_should_3d_array_convert():
field = get_field(types.ARRAY(types.Integer, dimensions=3))
assert isinstance(field.type, graphene.List)
assert isinstance(field.type.of_type, graphene.List)
assert isinstance(field.type.of_type.of_type, graphene.List)
assert field.type.of_type.of_type.of_type == graphene.Int


def test_should_postgresql_json_convert():
assert get_field(postgresql.JSON()).type == graphene.JSONString