generated from holaplex/hub-rust-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from holaplex/espi/1-of-1-mints
Standalone Collections & 1:1 Mints
- Loading branch information
Showing
31 changed files
with
1,701 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::collections::HashMap; | ||
|
||
use async_graphql::{dataloader::Loader as DataLoader, FieldError, Result}; | ||
use poem::async_trait; | ||
use sea_orm::{prelude::*, JoinType, QuerySelect}; | ||
|
||
use crate::{ | ||
db::Connection, | ||
entities::{collections, drops}, | ||
objects::Drop, | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Loader { | ||
pub db: Connection, | ||
} | ||
|
||
impl Loader { | ||
#[must_use] | ||
pub fn new(db: Connection) -> Self { | ||
Self { db } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl DataLoader<Uuid> for Loader { | ||
type Error = FieldError; | ||
type Value = Drop; | ||
|
||
async fn load(&self, keys: &[Uuid]) -> Result<HashMap<Uuid, Self::Value>, Self::Error> { | ||
let drops = drops::Entity::find() | ||
.join(JoinType::InnerJoin, drops::Relation::Collections.def()) | ||
.select_also(collections::Entity) | ||
.filter(drops::Column::CollectionId.is_in(keys.iter().map(ToOwned::to_owned))) | ||
.all(self.db.get()) | ||
.await?; | ||
|
||
drops | ||
.into_iter() | ||
.map(|(drop, collection)| { | ||
Ok(( | ||
drop.collection_id, | ||
Drop::new( | ||
drop.clone(), | ||
collection.ok_or(FieldError::new(format!( | ||
"no collection for the drop {}", | ||
drop.id | ||
)))?, | ||
), | ||
)) | ||
}) | ||
.collect::<Result<HashMap<Uuid, Self::Value>>>() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.