0.0
There's a lot of open issues
rails-fields gem provides robust field type enforcement for ActiveRecord models in Ruby on Rails applications. It includes utility methods for type validation, logging, and field mappings between GraphQL and ActiveRecord types Custom error classes provide clear diagnostics for field-related issues, making it easier to maintain consistent data models.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

>= 5.0
 Project Readme

Gem Version

Rails Fields

Enforce field types and attributes for ActiveRecord models in Ruby on Rails applications.

  • 🚀 Automatic ActiveRecord Migrations generation
  • 🦄 Automatic GraphQL types generation
  • 📝 Explicit declarative model attributes annotation
  • 💪🏻 Enforcement of fields declaration with real db columns
  • 📜 Automatic YARD model documentation

Description

The rails-fields gem provides robust field type enforcement for ActiveRecord models in Ruby on Rails applications. It includes utility methods for type validation, logging, and field mappings between GraphQL and ActiveRecord types. Custom error classes provide clear diagnostics for field-related issues, making it easier to maintain consistent data models.

Usage

In your ActiveRecord models:

class User < ApplicationRecord
  field :id, :integer
  field :created_at, :datetime
  field :updated_at, :datetime

  field :first_name, :string
  field :country, :string
  field :welcome, :string

  has_many :todos
  
  def welcome
    "Welcome #{first_name}!"
  end
end

Autogenerate GraphQL types using #gql_type class method:

module Types
  class QueryType < Types::BaseObject
    
    field :users, [User.gql_type], null: true
    
    def users
      User.all
    end
    
  end
end

Installation

Add this line to your application's Gemfile:

gem 'rails-fields'

If you want to have graphql types generated for your models, add this line to your application's Gemfile:

gem 'graphql'

Don't forget to install it $ ./bin/rails generate graphql:install

And then execute:

$ bundle install

License

The gem is available as open source under the terms of the MIT License.

Author

Gaston Morixe 2023 - gaston@gastonmorixe.com

rails-fields.dev