Class: ElasticGraph::GraphQL::QueryAdapter::Sort
- Inherits:
-
Data
- Object
- Data
- ElasticGraph::GraphQL::QueryAdapter::Sort
- Defined in:
- lib/elastic_graph/graphql/query_adapter/sort.rb
Overview
Note: This class is not tested directly but indirectly through specs on ‘QueryAdapter`
Instance Attribute Summary collapse
-
#order_by_arg_name ⇒ Object
readonly
Returns the value of attribute order_by_arg_name.
Instance Method Summary collapse
Instance Attribute Details
#order_by_arg_name ⇒ Object (readonly)
Returns the value of attribute order_by_arg_name
13 14 15 |
# File 'lib/elastic_graph/graphql/query_adapter/sort.rb', line 13 def order_by_arg_name @order_by_arg_name end |
Instance Method Details
#call(query:, args:, field:, lookahead:, context:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/elastic_graph/graphql/query_adapter/sort.rb', line 15 def call(query:, args:, field:, lookahead:, context:) sort_clauses = field.sort_clauses_for(args[order_by_arg_name]) if sort_clauses.empty? # When there are multiple search index definitions, we just need to pick one as the # source of the default sort clauses. It doesn't really matter which (if the client # really cared, they would have provided an `order_by` argument...) but we want our # logic to be consistent and deterministic, so we just use the alphabetically first # index here. sort_clauses = (_ = query.search_index_definitions.min_by(&:name)).default_sort_clauses end query.merge_with(sort: sort_clauses) end |