Class: ElasticGraph::GraphQL::Aggregation::QueryAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/graphql/aggregation/query_adapter.rb

Overview

Responsible for taking in the incoming GraphQL request context, arguments, and the GraphQL schema and directives and populating the ‘aggregations` portion of `query`.

Defined Under Namespace

Classes: WithoutSchema

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#element_namesObject (readonly)

Returns the value of attribute element_names.



57
58
59
# File 'lib/elastic_graph/graphql/aggregation/query_adapter.rb', line 57

def element_names
  @element_names
end

Instance Method Details

#call(query:, lookahead:, args:, field:, context:) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/elastic_graph/graphql/aggregation/query_adapter.rb', line 59

def call(query:, lookahead:, args:, field:, context:)
  aggregations_node = extract_aggregation_node(lookahead, field, context.query)
  return query unless aggregations_node

  aggregation_query = build_aggregation_query_for(
    aggregations_node,
    field: field,
    grouping_adapter: CompositeGroupingAdapter,
    # Filters on root aggregations applied to the search query body itself instead of
    # using a filter aggregation, like sub-aggregations do, so we don't want a filter
    # aggregation generated here.
    unfiltered: true
  )

  query.merge_with(aggregations: {aggregation_query.name => aggregation_query})
end