Skip to content

Instantly share code, notes, and snippets.

@msroot
Last active April 27, 2020 17:17
Show Gist options
  • Save msroot/5867f1dd09ff73d924d84bfd3e358592 to your computer and use it in GitHub Desktop.
Save msroot/5867f1dd09ff73d924d84bfd3e358592 to your computer and use it in GitHub Desktop.
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|
if value.present?
ids = klass.search(value, {execute: false, select: [:id]}).map(&:id)
scope.where(id: ids)
end
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment