Skip to content

Commit 2a2d74f

Browse files
committed
Fix for issue #288: 2D Array throws an error on GET
1 parent 20ecaea commit 2a2d74f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Diff for: graphene_sqlalchemy/converter.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,15 @@ def convert_scalar_list_to_list(type, column, registry=None):
234234
return List(String)
235235

236236

237+
def init_array_list_recursive(inner_type, n):
238+
return inner_type if n == 0 else List(init_array_list_recursive(inner_type, n-1))
239+
240+
237241
@convert_sqlalchemy_type.register(types.ARRAY)
238242
@convert_sqlalchemy_type.register(postgresql.ARRAY)
239243
def convert_array_to_list(_type, column, registry=None):
240244
inner_type = convert_sqlalchemy_type(column.type.item_type, column)
241-
return List(inner_type)
245+
return List(init_array_list_recursive(inner_type, (column.type.dimensions or 1) - 1))
242246

243247

244248
@convert_sqlalchemy_type.register(postgresql.HSTORE)

Diff for: graphene_sqlalchemy/tests/test_converter.py

+15
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,21 @@ def test_should_array_convert():
324324
assert field.type.of_type == graphene.Int
325325

326326

327+
def test_should_2d_array_convert():
328+
field = get_field(types.ARRAY(types.Integer, dimensions=2))
329+
assert isinstance(field.type, graphene.List)
330+
assert isinstance(field.type.of_type, graphene.List)
331+
assert field.type.of_type.of_type == graphene.Int
332+
333+
334+
def test_should_3d_array_convert():
335+
field = get_field(types.ARRAY(types.Integer, dimensions=3))
336+
assert isinstance(field.type, graphene.List)
337+
assert isinstance(field.type.of_type, graphene.List)
338+
assert isinstance(field.type.of_type.of_type, graphene.List)
339+
assert field.type.of_type.of_type.of_type == graphene.Int
340+
341+
327342
def test_should_postgresql_json_convert():
328343
assert get_field(postgresql.JSON()).type == graphene.JSONString
329344

0 commit comments

Comments
 (0)