use {
crate::types::graphql::{OrderTreeNodesGraphQL, OrderTreeRootGraphQL},
carbon_core::graphql::primitives::U8,
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "BookSide")]
pub struct BookSideGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub roots: Vec<OrderTreeRootGraphQL>,
pub reserved_roots: Vec<OrderTreeRootGraphQL>,
pub reserved: Vec<U8>,
pub nodes: OrderTreeNodesGraphQL,
}
impl TryFrom<crate::accounts::postgres::BookSideRow> for BookSideGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::BookSideRow) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
roots: row.roots.0.into_iter().map(|item| item.into()).collect(),
reserved_roots: row
.reserved_roots
.0
.into_iter()
.map(|item| item.into())
.collect(),
reserved: row
.reserved
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
nodes: row.nodes.0.into(),
})
}
}