This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Types | |
class BaseObject < GraphQL::Schema::Object | |
field_class Types::BaseField | |
def self.listable(name, object_type, name_suffix: "", override_options: {}) | |
list_type = Class.new(Types::BaseObject) do | |
graphql_name "#{name}#{name_suffix}" | |
field :rows, [object_type], null: true | |
field :totalCount, Integer, null: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
class Relation | |
def safe_order(field, direction = "asc") | |
direction = direction.downcase.to_sym | |
# NOTE: https://gist.github.com/amkisko/aec1283b9797e94348f89e3a2b934bc0 | |
raise Error::CustomError, code: "QUERY_ORDER_INVALID_DIRECTION" unless %i[asc desc].include?(direction) | |
# field = connection.quote_table_name(field) | |
order(field => direction) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Brakeman test | |
* Bundle audit test | |
* Rubocop test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "rubygems" | |
require "bundler/setup" | |
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) | |
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir) | |
# NOTE: https://github.com/piotrmurach/tty-command | |
require "tty-command" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rake" | |
RailsApp::Application.load_tasks | |
Rake::Task["my_task"].invoke |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveRecord::Relation | |
def efilter(filter) | |
where(ExtFilter.new(self, filter).to_s) | |
end | |
end | |
class ExtFilter | |
attr_accessor :relation | |
attr_accessor :conn | |
attr_accessor :filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FieldExtensions::ListExtension < GraphQL::Schema::FieldExtension | |
def apply | |
object_type = field.type.unwrap | |
list_type_name = object_type.graphql_name | |
namespace = options[:namespace] || "default" | |
list_type = | |
Class.new(Objects::BaseObject) do | |
self.graphql_name("#{namespace}_#{list_type_name}_list") | |
self.field(:rows, [object_type], null: true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
include Pundit | |
skip_forgery_protection | |
rescue_from(StandardError) do |err| | |
log_error(err) | |
if Rails.env.development? | |
render_error err | |
else | |
render_error Error::InternalServerError.new(code: err.class.to_s.sub(/:+/, "_").underscore.upcase) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BasicSchema < GraphQL::Schema | |
default_max_page_size 25 | |
use(GraphQL::Execution::Interpreter) | |
use(GraphQL::Analysis::AST) | |
query_analyzer(QueryAnalyzer) | |
use(GraphQL::Execution::Errors) | |
use(BatchLoader::GraphQL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NOTE: Add `config.exceptions_app = ExceptionsMiddleware.new` to application.rb | |
class ExceptionsMiddleware | |
def initialize | |
end | |
def call(env) | |
error = env["action_dispatch.exception"] | |
request = ActionDispatch::Request.new(env) |
OlderNewer