@@ -91,8 +91,6 @@ def convert_sqlalchemy_type(type, column, registry=None):
9191@convert_sqlalchemy_type .register (types .Text )
9292@convert_sqlalchemy_type .register (types .Unicode )
9393@convert_sqlalchemy_type .register (types .UnicodeText )
94- @convert_sqlalchemy_type .register (types .Enum )
95- @convert_sqlalchemy_type .register (postgresql .ENUM )
9694@convert_sqlalchemy_type .register (postgresql .UUID )
9795@convert_sqlalchemy_type .register (TSVectorType )
9896def convert_column_to_string (type , column , registry = None ):
@@ -111,22 +109,36 @@ def convert_column_to_datetime(type, column, registry=None):
111109@convert_sqlalchemy_type .register (types .Integer )
112110def convert_column_to_int_or_id (type , column , registry = None ):
113111 if column .primary_key :
114- return ID (description = get_column_doc (column ), required = not (is_column_nullable (column )))
112+ return ID (description = get_column_doc (column ),
113+ required = not (is_column_nullable (column )))
115114 else :
116115 return Int (description = get_column_doc (column ),
117116 required = not (is_column_nullable (column )))
118117
119118
120119@convert_sqlalchemy_type .register (types .Boolean )
121120def convert_column_to_boolean (type , column , registry = None ):
122- return Boolean (description = get_column_doc (column ), required = not (is_column_nullable (column )))
121+ return Boolean (description = get_column_doc (column ),
122+ required = not (is_column_nullable (column )))
123123
124124
125125@convert_sqlalchemy_type .register (types .Float )
126126@convert_sqlalchemy_type .register (types .Numeric )
127127@convert_sqlalchemy_type .register (types .BigInteger )
128128def convert_column_to_float (type , column , registry = None ):
129- return Float (description = get_column_doc (column ), required = not (is_column_nullable (column )))
129+ return Float (description = get_column_doc (column ),
130+ required = not (is_column_nullable (column )))
131+
132+
133+ @convert_sqlalchemy_type .register (types .Enum )
134+ def convert_enum_to_enum (type , column , registry = None ):
135+ try :
136+ items = type .enum_class .__members__ .items ()
137+ except AttributeError :
138+ items = zip (type .enums , type .enums )
139+ return Field (Enum (type .name , items ),
140+ description = get_column_doc (column ),
141+ required = not (is_column_nullable (column )))
130142
131143
132144@convert_sqlalchemy_type .register (ChoiceType )
@@ -144,16 +156,19 @@ def convert_scalar_list_to_list(type, column, registry=None):
144156def convert_postgres_array_to_list (_type , column , registry = None ):
145157 graphene_type = convert_sqlalchemy_type (column .type .item_type , column )
146158 inner_type = type (graphene_type )
147- return List (inner_type , description = get_column_doc (column ), required = not (is_column_nullable (column )))
159+ return List (inner_type , description = get_column_doc (column ),
160+ required = not (is_column_nullable (column )))
148161
149162
150163@convert_sqlalchemy_type .register (postgresql .HSTORE )
151164@convert_sqlalchemy_type .register (postgresql .JSON )
152165@convert_sqlalchemy_type .register (postgresql .JSONB )
153166def convert_json_to_string (type , column , registry = None ):
154- return JSONString (description = get_column_doc (column ), required = not (is_column_nullable (column )))
167+ return JSONString (description = get_column_doc (column ),
168+ required = not (is_column_nullable (column )))
155169
156170
157171@convert_sqlalchemy_type .register (JSONType )
158172def convert_json_type_to_string (type , column , registry = None ):
159- return JSONString (description = get_column_doc (column ), required = not (is_column_nullable (column )))
173+ return JSONString (description = get_column_doc (column ),
174+ required = not (is_column_nullable (column )))
0 commit comments