search.rb 919 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 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
  11. .new(
  12. current_user: context.current_user,
  13. query: search,
  14. objects: only_in ? [only_in] : Gql::Types::SearchResultType.searchable_models,
  15. options: { limit: limit }
  16. )
  17. .execute
  18. .flattened
  19. end
  20. end
  21. end