Class: HasHelpers::Resolvers::SearchQuery

Inherits:
GraphQL::Schema::Resolver
  • Object
show all
Defined in:
app/graphql/has_helpers/resolvers/search_query.rb

Instance Method Summary collapse

Instance Method Details

#resolve(resources:, query: "", filter: nil, options: nil) ⇒ Object



13
14
15
16
17
18
19
20
# File 'app/graphql/has_helpers/resolvers/search_query.rb', line 13

def resolve(resources:, query: "", filter: nil, options: nil)
  organization_id = context[:current_organization]&.id

  {
    results:
      search(resources, query, organization_id, filter, options)
  }
end

#search(resources_names, query, organization_id, filter, options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/graphql/has_helpers/resolvers/search_query.rb', line 22

def search(resources_names, query, organization_id, filter, options)
  # Add organization_id to options
  opts = (options.respond_to?(:to_kwargs) ? options.to_kwargs : options.to_h).deep_symbolize_keys
  opts[:with] = (opts[:with] || {}).merge(organization_id: organization_id)

  # All rails search should be sql search, elasticsearch search's should go to elixir
  result = HasHelpers::Search::SqlSearch.new.exec_query(
    resource: resources_names,
    query: query,
    options: opts,
    filter: filter
  )
  result.is_a?(Hash) ? result[:results] : (result || [])
end