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(ty.into().field_name_with_appendix(FIELD_JSON_SCHEMA_APPENDIX), TypeRef::named_nn("JSON"), move |_ctx| {
12        let schema = schema.clone();
13        FieldFuture::new(async move { Ok(to_field_value(schema.as_value().clone())) })
14    })
15}