Ibrain::Core

This is core plugin for rails api project

Usage

Please remove puma gem from your project before add this gem

Installation

Add this line to your application's Gemfile:

gem 'ibrain-core'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ibrain-core

Please install plugin after install this gem

$ bundle exec rails generate ibrain:install

Migration

Default migration engine is ridgepole, using this command line to migrate database:

bundle exec rails ridgpole:apply

To use default migration plugin, please disable ridgepole

bundle exec rails generate ibrain::install --with-ridgepole=false

GraphQL API

If you use graphql for rails please add this option when install plugin

$ bundle exec rails generate ibrain::install --with-graphql

To generate graphql type

bundle exec rails generate ibrain:graphql:object user

To generate graphql resolver single query to get user data

bundle exec rails generate ibrain:graphql:resolver user --model=User

To generate graphql resolvers query to get users list

bundle exec rails generate ibrain:graphql:resolvers users --model=User

To generate graphql resolver, mutation with prefix folder

bundle exec rails generate ibrain:graphql:resolvers users --model=User --prefix=admin

For pagination please using aggregate body query, something like

query users($offset: Int, $limit: Int, $filter: Filter) {
    users(offset: $offset, limit: $limit, filter: $filter) {
        id
        first_name
    }

    users_aggregate(filter: $filter) {
        total_count
    }
}

To generate graphql mutation to insert, update, delete user

bundle exec rails generate ibrain:graphql:mutation insert_user --model=User

Default all operation will be rejected if you not have Authorization Token at request header, so to skip authenticate please change parent_controller at ibrain.rb

config.parent_controller = "<Your parent controller>"

then create method skip_operations at this parent_controller

class ApplicationController < BaseController::API
    def skip_operations
        %w[sign_in].include?(operation_name)
    end
end

Contributing

Contribution directions go here.

License

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