Sha256: 14f1f876320495cbe2298e445a9df7828331e4dc1d1e4c83953b864d9494b088

Contents?: true

Size: 831 Bytes

Versions: 5

Compression:

Stored size: 831 Bytes

Contents

# frozen_string_literal: true

require '<%= folder %>/types/base_object'

module <%= namespace %>
  module Types
    class <%= model_name %>Type < BaseObject
      description 'A <%= model_name %>.'
      <%- if columns.include? :guid -%>
      field :id, ID, 'The unique GUID', null: false, resolver_method: :guid
      <%- end -%>
      <%- many_to_ones.each do |rel| -%>
      field :<%= rel[:table].to_s.singularize %>, '<%= namespace %>::Types::<%= rel[:table].to_s.classify %>Type', null: <%= schema[rel[:columns].first][:allow_null] %>
      <%- end -%>
      <%- schema.each do |name, info| -%>
      <%- next if %i[id guid].include?(name) || (name.to_s =~ /_id/ && info[:type] == :integer) -%>
      field :<%= name %>, <%= graphql_types[info[:type]] %>, null: <%= info[:allow_null] %>
      <%- end -%>
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ditty-0.11.1 lib/ditty/templates/type.rb.erb
ditty-0.10.2 lib/ditty/templates/type.rb.erb
ditty-0.10.1 lib/ditty/templates/type.rb.erb
ditty-0.9.1 lib/ditty/templates/type.rb.erb
ditty-0.9.0 lib/ditty/templates/type.rb.erb