Skip to content

Commit 1194f68

Browse files
committed
Add support for primary keys and null detection [fixes #7]
1 parent 2f7fe4f commit 1194f68

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/generators/gql/gql_generator_base.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ def map_model_types(model_name)
3131
klass.columns
3232
.reject { |col| bt_columns.include?(col.name) }
3333
.reject { |col| type_map[col.type].nil? }
34-
.map { |col| {name: col.name, gql_type: type_map[col.type]} }
34+
.map do |col|
35+
{
36+
name: col.name,
37+
null: col.null,
38+
gql_type: klass.primary_key == col.name ? 'GraphQL::Types::ID' : type_map[col.type]
39+
}
40+
end
3541
end
3642

3743
def root_directory(namespace)
@@ -54,7 +60,7 @@ def class_with_fields(namespace, name, superclass, fields)
5460
klass << sprintf("%sclass %s < %s", " " * indent, name, superclass)
5561

5662
fields.each do |field|
57-
klass << sprintf("%sfield :%s, %s, null: true", " " * (indent + 1), field[:name], field[:gql_type])
63+
klass << sprintf("%sfield :%s, %s, null: %s", " " * (indent + 1), field[:name], field[:gql_type], field[:null])
5864
end
5965

6066
klass << sprintf("%send", " " * indent)

0 commit comments

Comments
 (0)