use {
crate::types::graphql::PlaceOrderArgsGraphQL,
carbon_core::graphql::primitives::{I64, U64},
juniper::GraphQLObject,
serde_json,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "EditOrder")]
pub struct EditOrderGraphQL {
pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
pub client_order_id: U64,
pub expected_cancel_size: I64,
pub place_order: PlaceOrderArgsGraphQL,
pub accounts: carbon_core::graphql::primitives::Json,
}
impl TryFrom<crate::instructions::postgres::EditOrderRow> for EditOrderGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::instructions::postgres::EditOrderRow) -> Result<Self, Self::Error> {
Ok(Self {
instruction_metadata: row.instruction_metadata.into(),
client_order_id: carbon_core::graphql::primitives::U64(*row.client_order_id),
expected_cancel_size: carbon_core::graphql::primitives::I64(row.expected_cancel_size),
place_order: row.place_order.0.into(),
accounts: carbon_core::graphql::primitives::Json(
serde_json::to_value(&row.accounts.0)
.map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
),
})
}
}