subgraph/graphql/entity/create_field/
mod.rs

1use async_graphql::dynamic::{Field, FieldFuture, TypeRef};
2use log::debug;
3
4use crate::{
5    configuration::subgraph::entities::service_entity_field::ServiceEntityFieldConfig,
6    data_sources::DataSource,
7};
8
9use super::ServiceEntity;
10
11mod resolve_fields;
12mod resolve_nested;
13mod resolve_root;
14
15impl ServiceEntity {
16    pub fn create_field(
17        entity_field: ServiceEntityFieldConfig,
18        type_ref: TypeRef,
19        data_source: DataSource,
20        is_root_object: bool,
21        entity_required: bool,
22    ) -> Field {
23        debug!("Creating Field, {:?}", entity_field.name);
24
25        let field = Field::new(entity_field.name.clone(), type_ref, move |ctx| {
26            let cloned_entity_field = entity_field.clone();
27            let data_source = data_source.clone();
28
29            FieldFuture::new(async move {
30                debug!("Resolving Field: {:?}", cloned_entity_field.name);
31                match is_root_object {
32                    false => ServiceEntity::resolve_nested(&ctx, &cloned_entity_field),
33                    true => ServiceEntity::resolve_root(
34                        &ctx,
35                        &data_source,
36                        &cloned_entity_field,
37                        entity_required,
38                    ),
39                }
40            })
41        });
42
43        debug!("---Created Field: {:?}", field);
44
45        field
46    }
47}