subgraph/graphql/entity/create_field/resolve_nested/
mod.rs1use async_graphql::{dynamic::ResolverContext, Value};
2use log::{debug, trace};
3
4use crate::{
5 configuration::subgraph::entities::service_entity_field::ServiceEntityFieldConfig,
6 graphql::entity::ServiceEntity, utils::document::DocumentUtils,
7};
8
9mod get_parent_value;
10
11impl ServiceEntity {
12 pub fn resolve_nested(
13 ctx: &ResolverContext,
14 entity_field: &ServiceEntityFieldConfig,
15 ) -> Result<Option<Value>, async_graphql::Error> {
16 debug!("Resolving Nested Field");
17
18 let field_name = ctx.field().name();
19 trace!("Field Name: {:?}", field_name);
20
21 let parent_value = match ctx.parent_value.as_value() {
22 Some(value) => value,
23 None => {
24 trace!("Parent is none, returning none");
25 return Ok(None);
26 }
27 };
28 trace!("Parent Value: {:?}", parent_value);
29
30 let parent_value = ServiceEntity::get_parent_value(&parent_value, field_name)?;
31 trace!("Parent Value: {:?}", parent_value);
32
33 let document = DocumentUtils::json_to_document(&parent_value)?;
34
35 if document.is_none() {
36 trace!("Documenet is None, returning none");
37 return Ok(None);
38 }
39
40 let value = entity_field
41 .scalar
42 .clone()
43 .document_field_to_async_graphql_value(&document.unwrap(), &entity_field)?;
44
45 trace!("Resolved Nested Value: {:?}", value,);
46
47 Ok(value)
48 }
49}