Class: ElasticGraph::Apollo::GraphQL::EntitiesFieldResolver::RepresentationWithoutId
- Inherits:
-
Object
- Object
- ElasticGraph::Apollo::GraphQL::EntitiesFieldResolver::RepresentationWithoutId
- 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
-
#adapter ⇒ Object
Each ‘RepresentationWithoutId` instance needs to be handled by a separate adapter.
- #customize_query(query, representations) ⇒ Object
- #identify_matching_hit(indexed_search_hits, representation, context:, index:) ⇒ Object
- #index_search_hits(response) ⇒ Object
- #root_document_type? ⇒ Boolean
Instance Method Details
#adapter ⇒ Object
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.
244 245 246 |
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 244 def adapter self end |
#customize_query(query, representations) ⇒ Object
248 249 250 251 252 253 254 255 |
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 248 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}, internal_filters: [build_filter_for_hash(fields)] ) end |
#identify_matching_hit(indexed_search_hits, representation, context:, index:) ⇒ Object
261 262 263 264 265 266 267 268 269 |
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 261 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
257 258 259 |
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 257 def index_search_hits(response) {"search_hits" => response.to_a} end |
#root_document_type? ⇒ Boolean
271 272 273 |
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 271 def root_document_type? true end |