Module: Graphql::Generators::FieldExtractor

Included in:
InputGenerator, ObjectGenerator
Defined in:
lib/generators/graphql/field_extractor.rb

Instance Method Summary collapse

Instance Method Details

#column_type_string(column) ⇒ Object



20
21
22
# File 'lib/generators/graphql/field_extractor.rb', line 20

def column_type_string(column)
  column.name == "id" ? "ID" : column.type.to_s.camelize
end

#fieldsObject



7
8
9
10
11
# File 'lib/generators/graphql/field_extractor.rb', line 7

def fields
  columns = []
  columns += (klass&.columns&.map { |c| generate_column_string(c) }  || [])
  columns + custom_fields
end

#generate_column_string(column) ⇒ Object



13
14
15
16
17
18
# File 'lib/generators/graphql/field_extractor.rb', line 13

def generate_column_string(column)
  name = column.name
  required = column.null ? "" : "!"
  type = column_type_string(column)
  "#{name}:#{required}#{type}"
end

#klassObject



24
25
26
27
28
# File 'lib/generators/graphql/field_extractor.rb', line 24

def klass
  @klass ||= Module.const_get(name.camelize)
rescue NameError
  @klass = nil
end