Class: ElasticGraph::Apollo::GraphQL::EntitiesFieldResolver::RepresentationWithId::Adapter
- Inherits:
-
Data
- Object
- Data
- ElasticGraph::Apollo::GraphQL::EntitiesFieldResolver::RepresentationWithId::Adapter
- Defined in:
- lib/elastic_graph/apollo/graphql/entities_field_resolver.rb
Instance Attribute Summary collapse
-
#schema_element_names ⇒ Object
readonly
Returns the value of attribute schema_element_names.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#customize_query(query, representations) ⇒ ElasticGraph::GraphQL::DatastoreQuery
Customizes the given query to filter to entities matching the provided representations.
-
#identify_matching_hit(indexed_search_hits, representation, context:, index:) ⇒ Object
Given some indexed search hits and a representation, identifies the search hit that matches the representation.
-
#index_search_hits(response) ⇒ Object
Given a query response, indexes the search hits for easy ‘O(1)` retrieval by `identify_matching_hit`.
- #root_document_type? ⇒ Boolean
Instance Attribute Details
#schema_element_names ⇒ Object (readonly)
Returns the value of attribute schema_element_names
159 160 161 |
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 159 def schema_element_names @schema_element_names end |
#type ⇒ Object (readonly)
Returns the value of attribute type
159 160 161 |
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 159 def type @type end |
Instance Method Details
#customize_query(query, representations) ⇒ ElasticGraph::GraphQL::DatastoreQuery
Customizes the given query to filter to entities matching the provided representations. Builds a filter matching all IDs from the representations and configures pagination and requested fields.
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 169 def customize_query(query, representations) # Given a set of representations, builds a filter that will match all of them (and only them). all_ids = representations.map(&:id).reject { |id| id.is_a?(::Array) or id.is_a?(::Hash) } filter = {"id" => {schema_element_names.equal_to_any_of => all_ids}} query.merge_with( document_pagination: {first: representations.length}, requested_fields: additional_requested_fields_for(representations), internal_filters: [filter] ) end |
#identify_matching_hit(indexed_search_hits, representation, context:, index:) ⇒ Object
Given some indexed search hits and a representation, identifies the search hit that matches the representation.
188 189 190 191 |
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 188 def identify_matching_hit(indexed_search_hits, representation, context:, index:) hit = indexed_search_hits[representation.id] hit if hit && match?(representation.other_fields, hit.payload) end |
#index_search_hits(response) ⇒ Object
Given a query response, indexes the search hits for easy ‘O(1)` retrieval by `identify_matching_hit`. This allows us to provide `O(N)` complexity in our resolver instead of `O(N^2)`.
183 184 185 |
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 183 def index_search_hits(response) response.to_h { |hit| [hit.id, hit] } end |
#root_document_type? ⇒ Boolean
193 194 195 |
# File 'lib/elastic_graph/apollo/graphql/entities_field_resolver.rb', line 193 def root_document_type? true end |