@@ -23,6 +23,14 @@ class JSONType(object):
2323 pass
2424
2525
26+ def get_column_doc (column ):
27+ return getattr (column , 'doc' , None )
28+
29+
30+ def is_column_nullable (column ):
31+ return bool (getattr (column , 'nullable' , False ))
32+
33+
2634def convert_sqlalchemy_relationship (relationship , registry ):
2735 direction = relationship .direction
2836 model = relationship .mapper .entity
@@ -90,64 +98,64 @@ def convert_sqlalchemy_type(type, column, registry=None):
9098@convert_sqlalchemy_type .register (postgresql .ENUM )
9199@convert_sqlalchemy_type .register (postgresql .UUID )
92100def convert_column_to_string (type , column , registry = None ):
93- return String (description = getattr (column , 'doc' , None ),
94- required = not (getattr (column , 'nullable' , True )))
101+ return String (description = get_column_doc (column ),
102+ required = not (is_column_nullable (column )))
95103
96104
97105@convert_sqlalchemy_type .register (types .DateTime )
98106def convert_column_to_datetime (type , column , registry = None ):
99107 from graphene .types .datetime import DateTime
100- return DateTime (description = getattr (column , 'doc' , None ),
101- required = not (getattr (column , 'nullable' , True )))
108+ return DateTime (description = get_column_doc (column ),
109+ required = not (is_column_nullable (column )))
102110
103111
104112@convert_sqlalchemy_type .register (types .SmallInteger )
105113@convert_sqlalchemy_type .register (types .Integer )
106114def convert_column_to_int_or_id (type , column , registry = None ):
107115 if column .primary_key :
108- return ID (description = getattr (column , 'doc' , None ), required = not (getattr (column , 'nullable' , None )))
116+ return ID (description = get_column_doc (column ), required = not (is_column_nullable (column )))
109117 else :
110- return Int (description = getattr (column , 'doc' , None ),
111- required = not (getattr (column , 'nullable' , True )))
118+ return Int (description = get_column_doc (column ),
119+ required = not (is_column_nullable (column )))
112120
113121
114122@convert_sqlalchemy_type .register (types .Boolean )
115123def convert_column_to_boolean (type , column , registry = None ):
116- return Boolean (description = getattr (column , 'doc' , None ), required = not (getattr (column , 'nullable' , None )))
124+ return Boolean (description = get_column_doc (column ), required = not (is_column_nullable (column )))
117125
118126
119127@convert_sqlalchemy_type .register (types .Float )
120128@convert_sqlalchemy_type .register (types .Numeric )
121129@convert_sqlalchemy_type .register (types .BigInteger )
122130def convert_column_to_float (type , column , registry = None ):
123- return Float (description = getattr (column , 'doc' , None ), required = not (getattr (column , 'nullable' , None )))
131+ return Float (description = get_column_doc (column ), required = not (is_column_nullable (column )))
124132
125133
126134@convert_sqlalchemy_type .register (ChoiceType )
127135def convert_column_to_enum (type , column , registry = None ):
128136 name = '{}_{}' .format (column .table .name , column .name ).upper ()
129- return Enum (name , type .choices , description = getattr (column , 'doc' , None ))
137+ return Enum (name , type .choices , description = get_column_doc (column ))
130138
131139
132140@convert_sqlalchemy_type .register (ScalarListType )
133141def convert_scalar_list_to_list (type , column , registry = None ):
134- return List (String , description = getattr (column , 'doc' , None ))
142+ return List (String , description = get_column_doc (column ))
135143
136144
137145@convert_sqlalchemy_type .register (postgresql .ARRAY )
138146def convert_postgres_array_to_list (_type , column , registry = None ):
139147 graphene_type = convert_sqlalchemy_type (column .type .item_type , column )
140148 inner_type = type (graphene_type )
141- return List (inner_type , description = getattr (column , 'doc' , None ), required = not (getattr (column , 'nullable' , None )))
149+ return List (inner_type , description = get_column_doc (column ), required = not (is_column_nullable (column )))
142150
143151
144152@convert_sqlalchemy_type .register (postgresql .HSTORE )
145153@convert_sqlalchemy_type .register (postgresql .JSON )
146154@convert_sqlalchemy_type .register (postgresql .JSONB )
147155def convert_json_to_string (type , column , registry = None ):
148- return JSONString (description = getattr (column , 'doc' , None ), required = not (getattr (column , 'nullable' , None )))
156+ return JSONString (description = get_column_doc (column ), required = not (is_column_nullable (column )))
149157
150158
151159@convert_sqlalchemy_type .register (JSONType )
152160def convert_json_type_to_string (type , column , registry = None ):
153- return JSONString (description = getattr (column , 'doc' , None ), required = not (getattr (column , 'nullable' , None )))
161+ return JSONString (description = get_column_doc (column ), required = not (is_column_nullable (column )))
0 commit comments