search.rb 849 B

12345678910111213141516171819202122
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Queries
  3. class Search < BaseQuery
  4. description 'Generic object search'
  5. argument :search, String, description: 'What to search for'
  6. argument :only_in, Gql::Types::Enum::SearchableModelsType, required: false, description: 'Optionally restrict search to only_in one model'
  7. argument :limit, Integer, required: false, description: 'How many entries to find at maximum per model'
  8. type [Gql::Types::SearchResultType, { null: false }], null: false
  9. def resolve(search:, only_in: nil, limit: 10)
  10. Service::Search.new(current_user: context.current_user).execute(
  11. term: search,
  12. objects: only_in ? [only_in] : Gql::Types::SearchResultType.searchable_models,
  13. options: { limit: limit }
  14. )
  15. end
  16. end
  17. end