use {
crate::types::graphql::{
CollectionDetailsGraphQL, CollectionGraphQL, DataGraphQL, KeyGraphQL,
ProgrammableConfigGraphQL, TokenStandardGraphQL, UsesGraphQL,
},
carbon_core::graphql::primitives::{Pubkey, U8},
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "Metadata")]
pub struct MetadataGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub key: KeyGraphQL,
pub update_authority: Pubkey,
pub mint: Pubkey,
pub data: DataGraphQL,
pub primary_sale_happened: bool,
pub is_mutable: bool,
pub edition_nonce: Option<U8>,
pub token_standard: Option<TokenStandardGraphQL>,
pub collection: Option<CollectionGraphQL>,
pub uses: Option<UsesGraphQL>,
pub collection_details: Option<CollectionDetailsGraphQL>,
pub programmable_config: Option<ProgrammableConfigGraphQL>,
}
impl TryFrom<crate::accounts::postgres::MetadataRow> for MetadataGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::MetadataRow) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
key: row.key.0.into(),
update_authority: carbon_core::graphql::primitives::Pubkey(row.update_authority.0),
mint: carbon_core::graphql::primitives::Pubkey(row.mint.0),
data: row.data.0.into(),
primary_sale_happened: row.primary_sale_happened,
is_mutable: row.is_mutable,
edition_nonce: row
.edition_nonce
.map(|v| carbon_core::graphql::primitives::U8((*v) as u8)),
token_standard: row.token_standard.map(|v| v.0.into()),
collection: row.collection.map(|v| v.0.into()),
uses: row.uses.map(|v| v.0.into()),
collection_details: row.collection_details.map(|v| v.0.into()),
programmable_config: row.programmable_config.map(|v| v.0.into()),
})
}
}