use {juniper::GraphQLObject, serde_json};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "CpiEvent")]
pub struct CpiEventGraphQL {
pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
pub name: String,
pub data: carbon_core::graphql::primitives::Json,
pub accounts: carbon_core::graphql::primitives::Json,
}
impl TryFrom<crate::instructions::postgres::CpiEventRow> for CpiEventGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::instructions::postgres::CpiEventRow) -> Result<Self, Self::Error> {
Ok(Self {
instruction_metadata: row.instruction_metadata.into(),
name: row.name,
data: carbon_core::graphql::primitives::Json(
serde_json::to_value(row.data.0)
.map_err(|error| carbon_core::error::Error::Custom(error.to_string()))?,
),
accounts: carbon_core::graphql::primitives::Json(
serde_json::to_value(&row.accounts.0)
.map_err(|error| carbon_core::error::Error::Custom(error.to_string()))?,
),
})
}
}