Class: ElasticGraph::Apollo::GraphQL::EntitiesFieldResolver::RepresentationWithoutId

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/apollo/graphql/entities_field_resolver.rb

Overview

A simple value object containing a parsed form of an ‘_Any` representation when there’s no ‘id` field.

Instance Method Summary collapse

Instance Method Details

#adapterObject

Each ‘RepresentationWithoutId` instance needs to be handled by a separate adapter. We can’t safely combine representations into a single datastore query, so we want each to handled by a separate adapter instance. So, we use the representation itself as the adapter.



234
235
236
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 234

def adapter
  self
end

#customize_query(query, representations) ⇒ Object



238
239
240
241
242
243
244
245
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 238

def customize_query(query, representations)
  query.merge_with(
    # In the case of representations which don't query Id, we ask for 2 documents so that
    # if something weird is going on and it matches more than 1, we can detect that and return an error.
    document_pagination: {first: 2},
    filter: build_filter_for_hash(fields)
  )
end

#identify_matching_hit(indexed_search_hits, representation, context:, index:) ⇒ Object



251
252
253
254
255
256
257
258
259
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 251

def identify_matching_hit(indexed_search_hits, representation, context:, index:)
  search_hits = indexed_search_hits.fetch("search_hits")
  if search_hits.size > 1
    context.add_error(::GraphQL::ExecutionError.new("Representation at index #{index} matches more than one entity."))
    nil
  else
    search_hits.first
  end
end

#index_search_hits(response) ⇒ Object



247
248
249
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 247

def index_search_hits(response)
  {"search_hits" => response.to_a}
end

#indexed?Boolean

Returns:

  • (Boolean)


261
262
263
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 261

def indexed?
  true
end