Skip to content

Instantly share code, notes, and snippets.

View msroot's full-sized avatar
:octocat:

Yannis Kolovos msroot

:octocat:
View GitHub Profile
module Types
class QueryType < Types::BaseObject
field :users, resolver: Resolvers::UsersResolver
end
end
@msroot
msroot / base_search_resolver.rb
Last active April 27, 2020 23:51
BaseSearchResolver order_by, search, totalcount and order_by helpers
require 'search_object'
require 'search_object/plugin/graphql'
module Resolvers
class BaseSearchResolver
include ::SearchObject.module(:graphql)
scope { [] }
FILTER_BY_DATE_INPUT = begin
module Resolvers
class UsersResolver < Resolvers::BaseSearchResolver
type Types::UserType.connection_type, null: false
scope { User.all }
add_search_for(User)
end
end
require 'search_object'
require 'search_object/plugin/graphql'
module Resolvers
class BaseSearchResolver
include ::SearchObject.module(:graphql)
scope { [] }
def self.add_search_for(klass)
option(:search, type: String) { |scope, value|
module Resolvers
class UsersResolver < Resolvers::BaseSearchResolver
type Types::UserType.connection_type, null: false
scope { User.all }
add_filter_by_datetime_for(User)
end
end
require 'search_object'
require 'search_object/plugin/graphql'
module Resolvers
class BaseSearchResolver
include ::SearchObject.module(:graphql)
scope { [] }
FILTER_BY_DATE_INPUT = begin
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def self.datetime_attributes
@datetime_attributes ||= columns_hash.select {|k,v| v.type == :datetime}.keys.sort
end
end
module Resolvers
class UsersResolver < Resolvers::BaseSearchResolver
type Types::UserType.connection_type, null: false
scope { User.all }
add_order_by_for(User)
end
end
require 'search_object'
require 'search_object/plugin/graphql'
module Resolvers
class BaseSearchResolver
include ::SearchObject.module(:graphql)
ORDER_BY_DIRECTION_INPUT = begin
Class.new(Types::BaseEnum) do
graphql_name "OrderByDirection"
@msroot
msroot / garfield_policy.rb
Last active April 1, 2020 19:19
Simple field authorization Ruby GraphQL
# Add the GarfieldPolicy to GraphQL directory
class GarfieldPolicy
attr_accessor :field
attr_accessor :options
def initialize(field:, options:)
@field = field
@options = options || {}
apply
freeze