Class: ElasticGraph::GraphQL::Aggregation::Resolvers::AggregatedValues
- Inherits:
-
Object
- Object
- ElasticGraph::GraphQL::Aggregation::Resolvers::AggregatedValues
- Defined in:
- lib/elastic_graph/graphql/aggregation/resolvers/aggregated_values.rb
Instance Method Summary collapse
- #can_resolve?(field:, object:) ⇒ Boolean
- #resolve(field:, object:, args:, context:, lookahead:) ⇒ Object
Instance Method Details
#can_resolve?(field:, object:) ⇒ Boolean
18 19 20 |
# File 'lib/elastic_graph/graphql/aggregation/resolvers/aggregated_values.rb', line 18 def can_resolve?(field:, object:) true end |
#resolve(field:, object:, args:, context:, lookahead:) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/elastic_graph/graphql/aggregation/resolvers/aggregated_values.rb', line 22 def resolve(field:, object:, args:, context:, lookahead:) return with(field_path: field_path + [PathSegment.for(field: field, lookahead: lookahead)]) if field.type.object? key = Key::AggregatedValue.new( aggregation_name: aggregation_name, field_path: field_path.map(&:name_in_graphql_query), function_name: field.name_in_index.to_s ) result = Support::HashUtil.verbose_fetch(bucket, key.encode) # Aggregated value results always have a `value` key; in addition, for `date` field, they also have a `value_as_string`. # In that case, `value` is a number (e.g. ms since epoch) whereas `value_as_string` is a formatted value. ElasticGraph # works with date types as formatted strings, so we need to use `value_as_string` here if it is present. result.fetch("value_as_string") { result.fetch("value") } end |