Class: ElasticGraph::GraphQL::Resolvers::GetRecordFieldValue
- Inherits:
-
Object
- Object
- ElasticGraph::GraphQL::Resolvers::GetRecordFieldValue
- Defined in:
- lib/elastic_graph/graphql/resolvers/get_record_field_value.rb
Overview
Responsible for fetching a single field value from a document.
Instance Method Summary collapse
-
#initialize(elasticgraph_graphql:, config:) ⇒ GetRecordFieldValue
constructor
A new instance of GetRecordFieldValue.
- #resolve(field:, object:, args:, context:) ⇒ Object
Constructor Details
#initialize(elasticgraph_graphql:, config:) ⇒ GetRecordFieldValue
Returns a new instance of GetRecordFieldValue.
18 19 |
# File 'lib/elastic_graph/graphql/resolvers/get_record_field_value.rb', line 18 def initialize(elasticgraph_graphql:, config:) end |
Instance Method Details
#resolve(field:, object:, args:, context:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/elastic_graph/graphql/resolvers/get_record_field_value.rb', line 21 def resolve(field:, object:, args:, context:) data = case object when DatastoreResponse::Document object.payload else object end value = Support::HashUtil.fetch_value_at_path(data, field.path_in_index) { nil } value = [] if value.nil? && field.type.list? if field.type.relay_connection? RelayConnection::ArrayAdapter.build(value, args, context) else value end end |