use {
crate::types::graphql::KeyGraphQL, carbon_core::graphql::primitives::Pubkey,
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "GroupV1")]
pub struct GroupV1GraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub key: KeyGraphQL,
pub update_authority: Pubkey,
pub name: String,
pub uri: String,
pub collections: Vec<Pubkey>,
pub groups: Vec<Pubkey>,
pub parent_groups: Vec<Pubkey>,
pub assets: Vec<Pubkey>,
}
impl TryFrom<crate::accounts::postgres::GroupV1Row> for GroupV1GraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::GroupV1Row) -> 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),
name: row.name,
uri: row.uri,
collections: row
.collections
.into_iter()
.map(|item| carbon_core::graphql::primitives::Pubkey(item.0))
.collect(),
groups: row
.groups
.into_iter()
.map(|item| carbon_core::graphql::primitives::Pubkey(item.0))
.collect(),
parent_groups: row
.parent_groups
.into_iter()
.map(|item| carbon_core::graphql::primitives::Pubkey(item.0))
.collect(),
assets: row
.assets
.into_iter()
.map(|item| carbon_core::graphql::primitives::Pubkey(item.0))
.collect(),
})
}
}