Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project Analytics Refactor #6

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ async-graphql = { version = "5.0.4", features = [
"apollo_tracing",
] }
async-graphql-poem = "5.0.3"
serde = { version = "1.0.152", features = ["derive"] }
serde = { version = "1.0.188", features = ["derive"] }
serde_derive = { version = "1.0.188" }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove.

serde_json = { version = "1.0.91" }
prost = "0.11.6"
cube-client = { version = "0.1.2", git = "https://github.com/holaplex/cube-client", branch = "dev" }
Expand Down
14 changes: 12 additions & 2 deletions app/src/cube_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use hub_core::{
clap, thiserror,
url::Url,
};
use serde::de::DeserializeOwned;

/// Arguments for establishing a database connection
#[derive(Clone, Debug, clap::Args)]
Expand Down Expand Up @@ -49,13 +50,22 @@ impl Client {
///
/// # Errors
/// This function fails if query parameters are invalid or Cube is not responding
pub async fn query(&self, query: Query) -> Result<String, CubeClientError> {
pub async fn query<T: DeserializeOwned>(
&self,
query: Query,
) -> Result<Vec<T>, CubeClientError> {
let request = V1LoadRequest {
query: Some(query.build()),
query_type: Some("multi".to_string()),
};

let response = cube_api::load_v1(&self.0, Some(request)).await?;
Ok(serde_json::to_string(&response)?)

response.results[0]
.data
.iter()
.map(|value| serde_json::from_value(value.clone()))
.collect::<Result<Vec<T>, serde_json::Error>>()
.map_err(Into::into)
}
}
15 changes: 15 additions & 0 deletions app/src/entities/customers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1

use async_graphql::Enum;
use sea_orm::entity::prelude::*;

#[derive(Clone, Copy, Enum, Debug, PartialEq, Eq)]
#[graphql(name = "CustomerDimension")]
pub enum Dimension {
ProjectId,
}

impl ToString for Dimension {
fn to_string(&self) -> String {
match self {
Self::ProjectId => String::from("mints.project_id"),
}
}
}

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "customers")]
pub struct Model {
Expand Down
17 changes: 17 additions & 0 deletions app/src/entities/mints.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1

use async_graphql::Enum;
use sea_orm::entity::prelude::*;

#[derive(Clone, Copy, Enum, Debug, PartialEq, Eq)]
#[graphql(name = "MintDimension")]
pub enum Dimension {
ProjectId,
CollectionId,
}

impl ToString for Dimension {
fn to_string(&self) -> String {
match self {
Self::ProjectId => String::from("mints.project_id"),
Self::CollectionId => String::from("mints.collection_id"),
}
}
}

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "mints")]
pub struct Model {
Expand Down
28 changes: 7 additions & 21 deletions app/src/graphql/objects/collection.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use async_graphql::{ComplexObject, Context, Result, SimpleObject};
use hub_core::uuid::Uuid;

use crate::graphql::{
objects::{DataPoint, Interval, Order},
queries::analytics::Query,
};
use crate::graphql::objects::{Interval, Order};

#[derive(Debug, Clone, SimpleObject)]
#[graphql(complex)]
Expand All @@ -15,24 +12,13 @@

#[ComplexObject]
impl Collection {
#[allow(clippy::too_many_arguments)]
async fn analytics(

Check warning on line 15 in app/src/graphql/objects/collection.rs

View workflow job for this annotation

GitHub Actions / clippy/check/doc

unused `async` for function with no await statements
&self,
ctx: &Context<'_>,
interval: Option<Interval>,
order: Option<Order>,
limit: Option<i32>,
) -> Result<Vec<DataPoint>> {
Query::analytics(
&Query,
ctx,
None,
None,
Some(self.id),
interval,
order,
limit,
)
.await
_ctx: &Context<'_>,
_interval: Option<Interval>,
_order: Option<Order>,
_limit: Option<i32>,
) -> Result<String> {
Ok(String::new())
}
}
Loading
Loading