Class: ElasticGraph::GraphQL::Aggregation::Resolvers::SubAggregations

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

Instance Method Summary collapse

Instance Method Details

#can_resolve?(field:, object:) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/elastic_graph/graphql/aggregation/resolvers/sub_aggregations.rb', line 23

def can_resolve?(field:, object:)
  true
end

#resolve(field:, object:, args:, context:, lookahead:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/elastic_graph/graphql/aggregation/resolvers/sub_aggregations.rb', line 27

def resolve(field:, object:, args:, context:, lookahead:)
  path_segment = PathSegment.for(field: field, lookahead: lookahead)
  new_field_path = field_path + [path_segment]
  return with(field_path: new_field_path) unless field.type.elasticgraph_category == :nested_sub_aggregation_connection

  sub_agg_key = FieldPathEncoder.encode(new_field_path.map(&:name_in_graphql_query))
  sub_agg_query = Support::HashUtil.verbose_fetch(sub_aggregations, sub_agg_key).query

  RelayConnectionBuilder.build_from_buckets(
    query: sub_agg_query,
    parent_queries: parent_queries,
    schema_element_names: schema_element_names,
    field_path: new_field_path
  ) { extract_buckets(sub_agg_key, args) }
end