Skip to content

Commit 2bced89

Browse files
authored
Merge pull request #2 from sjhewitt/convert-label-column
handle conversion of label columns
2 parents c69017e + 0077f6a commit 2bced89

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

graphene_sqlalchemy/converter.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ def convert_sqlalchemy_type(type, column, registry=None):
8787
@convert_sqlalchemy_type.register(postgresql.ENUM)
8888
@convert_sqlalchemy_type.register(postgresql.UUID)
8989
def convert_column_to_string(type, column, registry=None):
90-
return String(description=column.doc, required=not(column.nullable))
90+
return String(description=getattr(column, 'doc', None),
91+
required=not(getattr(column, 'nullable', True)))
9192

9293

9394
@convert_sqlalchemy_type.register(types.SmallInteger)

graphene_sqlalchemy/tests/test_converter.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from py.test import raises
2-
from sqlalchemy import Column, Table, types
2+
from sqlalchemy import Column, Table, case, types
33
from sqlalchemy.dialects import postgresql
44
from sqlalchemy.ext.declarative import declarative_base
55
from sqlalchemy.orm import composite
6+
from sqlalchemy.sql.elements import Label
67
from sqlalchemy_utils import ChoiceType, ScalarListType
78

89
import graphene
@@ -106,6 +107,12 @@ def test_should_numeric_convert_float():
106107
assert_column_conversion(types.Numeric(), graphene.Float)
107108

108109

110+
def test_should_label_convert_string():
111+
label = Label('label_test', case([], else_="foo"), type_=types.Unicode())
112+
graphene_type = convert_sqlalchemy_column(label)
113+
assert isinstance(graphene_type, graphene.String)
114+
115+
109116
def test_should_choice_convert_enum():
110117
TYPES = [
111118
(u'es', u'Spanish'),

0 commit comments

Comments
 (0)