Class: GraphSQL::Generators::TypeGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- GraphSQL::Generators::TypeGenerator
- Defined in:
- lib/generators/graphsql/type/type_generator.rb
Overview
rails generate graphsql:type Persona
Introspects an already-migrated ActiveRecord model's columns and
associations and emits a matching GraphSQL::Mapping type — every
column gets a graphsql_column + field pair, every association gets a
graphsql_association + field pair (plus a lookahead-driven resolver
method for collection associations), and to: is guessed for every
non-polymorphic association as "<type_namespace>::
This only works against a model whose table already exists — it reads real column/association metadata via ActiveRecord, it doesn't infer anything from a migration file. Generate the model (and run its migration) first, then generate its type.
Defined Under Namespace
Classes: MappedAssociation, MappedColumn
Constant Summary collapse
- SCALAR_TYPES =
{ "string" => "String", "text" => "String", "citext" => "String", "integer" => "Integer", "bigint" => "Integer", "float" => "Float", "decimal" => "Float", "boolean" => "Boolean", "date" => "GraphQL::Types::ISO8601Date", "datetime" => "GraphQL::Types::ISO8601DateTime", "timestamp" => "GraphQL::Types::ISO8601DateTime", "json" => "GraphQL::Types::JSON", "jsonb" => "GraphQL::Types::JSON" }.freeze
Instance Method Summary collapse
Instance Method Details
#add_query_field ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/generators/graphsql/type/type_generator.rb', line 54 def add_query_field return if [:skip_query] unless File.exist?(File.join(destination_root, query_type_path)) say_status :skip, "#{query_type_path} not found (pass --query-type-path or add the field by hand)", :yellow return end inject_into_class query_type_path, [:query_type_class_name], query_field_snippet end |
#create_type_file ⇒ Object
50 51 52 |
# File 'lib/generators/graphsql/type/type_generator.rb', line 50 def create_type_file template "type.rb.tt", File.join("app/graphql/types", "#{file_name}_type.rb") end |