reactive_graph_dynamic_graph_impl/object/namespace/
schema.rs

1use crate::field::to_field_value;
2use crate::object::types::DynamicGraphTypeDefinition;
3use async_graphql::dynamic::Field;
4use async_graphql::dynamic::FieldFuture;
5use async_graphql::dynamic::TypeRef;
6use schemars::Schema;
7
8pub const FIELD_JSON_SCHEMA_APPENDIX: &str = "JsonSchema";
9
10pub fn json_schema_field<TY: Into<DynamicGraphTypeDefinition>>(ty: TY, schema: Schema) -> Field {
11    Field::new(
12        ty.into().field_name_with_suffix_and_appendix(FIELD_JSON_SCHEMA_APPENDIX),
13        TypeRef::named_nn("JSON"),
14        move |_ctx| {
15            let schema = schema.clone();
16            FieldFuture::new(async move { Ok(to_field_value(schema.as_value().clone())) })
17        },
18    )
19}