Class: GraphQL::Searchkick::SearchableExtension
- Inherits:
-
GraphQL::Schema::FieldExtension
- Object
- GraphQL::Schema::FieldExtension
- GraphQL::Searchkick::SearchableExtension
- Defined in:
- lib/graphql/searchkick/searchable_extension.rb
Instance Method Summary collapse
Instance Method Details
#apply ⇒ Object
8 9 10 |
# File 'lib/graphql/searchkick/searchable_extension.rb', line 8 def apply field.argument(:query, String, required: false, description: 'A search query') end |
#resolve(object:, arguments:, context:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/graphql/searchkick/searchable_extension.rb', line 12 def resolve(object:, arguments:, context:) next_args = arguments.dup result = yield(object, next_args) if defined?(ActiveRecord::Relation) && result.is_a?(ActiveRecord::Relation) result else model = [:model_class] LazySearch.new(result, query: next_args[:query], model_class: model) end end |