Class: Graphql::Generators::ObjectGenerator
- Inherits:
-
TypeGeneratorBase
- Object
- Rails::Generators::Base
- TypeGeneratorBase
- Graphql::Generators::ObjectGenerator
- Defined in:
- lib/generators/graphql/object_generator.rb
Overview
Generate an object type by name, with the specified fields.
rails g graphql:object PostType name:String!
Add the Node interface with --node
.
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Core
#create_dir, #create_mutation_root_type, #insert_root_type, #module_namespacing_when_supported, #schema_file_path
Class Method Details
.normalize_type_expression(type_expression, mode:, null: true) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/generators/graphql/object_generator.rb', line 40 def self.normalize_type_expression(type_expression, mode:, null: true) case type_expression when "Text" ["String", null] when "Decimal" ["Float", null] when "DateTime", "Datetime" ["GraphQL::Types::ISO8601DateTime", null] when "Date" ["GraphQL::Types::ISO8601Date", null] else super end end |
Instance Method Details
#create_type_file ⇒ Object
30 31 32 |
# File 'lib/generators/graphql/object_generator.rb', line 30 def create_type_file template "object.erb", "#{[:directory]}/types/#{type_file_name}.rb" end |
#fields ⇒ Object
34 35 36 37 38 |
# File 'lib/generators/graphql/object_generator.rb', line 34 def fields columns = [] columns += klass.columns.map { |c| generate_column_string(c) } if class_exists? columns + custom_fields end |