Skip to content

handle conversion of label columns #2

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
3 changes: 2 additions & 1 deletion graphene_sqlalchemy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def convert_sqlalchemy_type(type, column, registry=None):
@convert_sqlalchemy_type.register(postgresql.ENUM)
@convert_sqlalchemy_type.register(postgresql.UUID)
def convert_column_to_string(type, column, registry=None):
return String(description=column.doc, required=not(column.nullable))
return String(description=getattr(column, 'doc', None),
required=not(getattr(column, 'nullable', True)))


@convert_sqlalchemy_type.register(types.SmallInteger)
Expand Down
9 changes: 8 additions & 1 deletion graphene_sqlalchemy/tests/test_converter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from py.test import raises
from sqlalchemy import Column, Table, types
from sqlalchemy import Column, Table, case, types
from sqlalchemy.dialects import postgresql
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import composite
from sqlalchemy.sql.elements import Label
from sqlalchemy_utils import ChoiceType, ScalarListType

import graphene
Expand Down Expand Up @@ -106,6 +107,12 @@ def test_should_numeric_convert_float():
assert_column_conversion(types.Numeric(), graphene.Float)


def test_should_label_convert_string():
label = Label('label_test', case([], else_="foo"), type_=types.Unicode())
graphene_type = convert_sqlalchemy_column(label)
assert isinstance(graphene_type, graphene.String)


def test_should_choice_convert_enum():
TYPES = [
(u'es', u'Spanish'),
Expand Down