Class: ElasticGraph::GraphQL::Resolvers::RelayConnection::DocumentEdge

Inherits:
GenericAdapter::Edge show all
Defined in:
lib/elastic_graph/graphql/resolvers/relay_connection/search_response_adapter_builder.rb

Instance Method Summary collapse

Methods inherited from GenericAdapter::Edge

#cursor

Instance Method Details

#all_highlightsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/elastic_graph/graphql/resolvers/relay_connection/search_response_adapter_builder.rb', line 48

def all_highlights
  @all_highlights ||= begin
    document_type =
      if (typename = node["__typename"])
        # When multiple types share an index, documents carry a `__typename` field
        # that identifies the concrete type; use it to resolve the concrete type directly.
        schema.type_named(typename)
      else
        # Index inheritance always injects `__typename` into any shared index mapping,
        # so a missing `__typename` means no sharing — the set contains exactly one type.
        schema.document_types_stored_in(node.index_definition_name).first # : Schema::Type
      end

    node.highlights.filter_map do |path_string, snippets|
      if (path = path_from(path_string, document_type))
        SearchHighlight.new(schema, path, snippets)
      end
    end.sort_by(&:path)
  end
end

#highlightsObject



40
41
42
43
44
45
46
# File 'lib/elastic_graph/graphql/resolvers/relay_connection/search_response_adapter_builder.rb', line 40

def highlights
  @highlights ||= node.highlights.each_with_object({}) do |(path_string, snippets), highlights| # $::Hash[::String, untyped]
    *object_fields, leaf_field = path_string.split(".")
    leaf_hash = object_fields.reduce(highlights) { |accum, field| accum[field] ||= {} }
    leaf_hash[leaf_field.to_s] = snippets
  end
end