Skip to content

Commit

Permalink
Merge pull request #184 from holaplex/espi/collection-mint-query
Browse files Browse the repository at this point in the history
Query mint by ID
  • Loading branch information
kespinola authored Aug 11, 2023
2 parents 358861c + 20b2086 commit b047032
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/src/dataloaders/update_histories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl DataLoader<Uuid> for UpdateMintHistoryLoader {
acc.entry(history.mint_id).or_insert_with(Vec::new);

acc.entry(history.mint_id)
.and_modify(|update_histories| update_histories.push(history.into()));
.and_modify(|update_histories| update_histories.push(history));

acc
}))
Expand Down
3 changes: 1 addition & 2 deletions api/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ use crate::{
Attribute, CreationStatus as NftCreationStatus, DropCreation, File, Metadata,
MintCollectionCreation, MintCreation, MintOwnershipUpdate, MintedTokensOwnershipUpdate,
NftEventKey, NftEvents, SolanaCollectionPayload, SolanaCompletedMintTransaction,
SolanaCompletedTransferTransaction, SolanaMintPayload, SolanaNftEventKey,
SolanaUpdatedMintPayload, TreasuryEventKey,
SolanaCompletedTransferTransaction, SolanaMintPayload, SolanaNftEventKey, TreasuryEventKey,
},
Actions, Services,
};
Expand Down
6 changes: 6 additions & 0 deletions api/src/mutations/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ impl Mutation {
})
}

/// This mutation updates a mint.
/// # Errors
/// If the mint cannot be saved to the database or fails to be emitted for submission to the desired blockchain, the mutation will result in an error.
pub async fn update_mint(
&self,
ctx: &Context<'_>,
Expand Down Expand Up @@ -651,6 +654,9 @@ impl Mutation {
})
}

/// This mutation retries updating a mint that failed by providing the ID of the `update_history`.
/// # Errors
/// If the mint cannot be saved to the database or fails to be emitted for submission to the desired blockchain, the mutation will result in an error.
pub async fn retry_update_mint(
&self,
ctx: &Context<'_>,
Expand Down
3 changes: 3 additions & 0 deletions api/src/objects/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl Project {
}

/// Look up a drop associated with the project by its ID.
#[graphql(deprecation = "Use `drop` root query field instead")]
async fn drop(&self, ctx: &Context<'_>, id: Uuid) -> Result<Option<Drop>> {
let AppContext { drop_loader, .. } = ctx.data::<AppContext>()?;

Expand Down Expand Up @@ -54,6 +55,8 @@ impl Project {
project_collections_loader.load_one(self.id).await
}

/// Look up a collection associated with the project by its ID.
#[graphql(deprecation = "Use `collection` root query field instead")]
async fn collection(&self, ctx: &Context<'_>, id: Uuid) -> Result<Option<Collection>> {
let AppContext {
project_collection_loader,
Expand Down
20 changes: 20 additions & 0 deletions api/src/queries/collection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use async_graphql::{Context, Object, Result};
use hub_core::uuid::Uuid;

use crate::{objects::Collection, AppContext};

#[derive(Debug, Clone, Copy, Default)]
pub struct Query;

#[Object(name = "CollectionQuery")]
impl Query {
/// Look up a `collection` by its ID.
async fn collection(&self, ctx: &Context<'_>, id: Uuid) -> Result<Option<Collection>> {
let AppContext {
project_collection_loader,
..
} = ctx.data::<AppContext>()?;

project_collection_loader.load_one(id).await
}
}
17 changes: 17 additions & 0 deletions api/src/queries/drop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use async_graphql::{Context, Object, Result};
use hub_core::uuid::Uuid;

use crate::{objects::Drop, AppContext};

#[derive(Debug, Clone, Copy, Default)]
pub struct Query;

#[Object(name = "DropQuery")]
impl Query {
/// Look up a `drop` by its ID.
async fn drop(&self, ctx: &Context<'_>, id: Uuid) -> Result<Option<Drop>> {
let AppContext { drop_loader, .. } = ctx.data::<AppContext>()?;

drop_loader.load_one(id).await
}
}
20 changes: 20 additions & 0 deletions api/src/queries/mint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use async_graphql::{Context, Object, Result};
use hub_core::uuid::Uuid;

use crate::{entities::collection_mints::CollectionMint, AppContext};

#[derive(Debug, Clone, Copy, Default)]
pub struct Query;

#[Object(name = "MintQuery")]
impl Query {
/// Look up a `collection_mint` by its ID.
async fn mint(&self, ctx: &Context<'_>, id: Uuid) -> Result<Option<CollectionMint>> {
let AppContext {
single_collection_mint_loader,
..
} = ctx.data::<AppContext>()?;

single_collection_mint_loader.load_one(id).await
}
}
12 changes: 11 additions & 1 deletion api/src/queries/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#![allow(clippy::unused_async)]

mod collection;
mod customer;
mod drop;
mod mint;
mod project;
mod wallet;

// // Add your other ones here to create a unified Query object
#[derive(async_graphql::MergedObject, Default)]
pub struct Query(project::Query, wallet::Query, customer::Query);
pub struct Query(
project::Query,
wallet::Query,
customer::Query,
mint::Query,
collection::Query,
drop::Query,
);

0 comments on commit b047032

Please sign in to comment.