Sha256: f30d2be1f34d6e4842d9224dbd498ac2f3bec1bdfae4610b4414179c7ebae980
Contents?: true
Size: 1.44 KB
Versions: 120
Compression:
Stored size: 1.44 KB
Contents
# frozen_string_literal: true require 'generators/graphql/type_generator' require 'generators/graphql/field_extractor' module Graphql module Generators # Generate an object type by name, # with the specified fields. # # ``` # rails g graphql:object PostType name:String! # ``` # # Add the Node interface with `--node`. class ObjectGenerator < TypeGeneratorBase desc "Create a GraphQL::ObjectType with the given name and fields." \ "If the given type name matches an existing ActiveRecord model, the generated type will automatically include fields for the models database columns." source_root File.expand_path('../templates', __FILE__) include FieldExtractor class_option :node, type: :boolean, default: false, desc: "Include the Relay Node interface" def self.normalize_type_expression(type_expression, mode:, null: true) case type_expression.camelize when "Text", "Citext" ["String", null] when "Decimal" ["Float", null] when "DateTime", "Datetime" ["GraphQL::Types::ISO8601DateTime", null] when "Date" ["GraphQL::Types::ISO8601Date", null] when "Json", "Jsonb", "Hstore" ["GraphQL::Types::JSON", null] else super end end private def graphql_type "object" end end end end
Version data entries
120 entries across 120 versions & 1 rubygems