Skip to content

Commit

Permalink
Update reference resolvers for router
Browse files Browse the repository at this point in the history
  • Loading branch information
iamvigneshwars committed Mar 22, 2024
1 parent 53300de commit 23c4cfd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
10 changes: 5 additions & 5 deletions graph-data-processing/src/graphql/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use async_graphql::SimpleObject;
use models::data_collection_file_attachment;

#[derive(Clone, Debug, PartialEq, SimpleObject)]
#[graphql(name = "DataProcessing")]
#[graphql(name = "DataProcessing", unresolvable)]
pub struct DataProcessing {

Check failure on line 6 in graph-data-processing/src/graphql/entities.rs

View workflow job for this annotation

GitHub Actions / lint

missing documentation for a struct
/// An opaque unique identifier for the collected file attachment
pub data_collection_file_attachment_id: u32,
/// An opaque unique identifier for the collected file attachment
pub data_collection_file_attachment_id: u32,
/// Full path where the processed image is stored
pub file_full_path: String,
pub file_full_path: String,
}

impl From<data_collection_file_attachment::Model> for DataProcessing {
Expand All @@ -23,5 +23,5 @@ impl From<data_collection_file_attachment::Model> for DataProcessing {
#[graphql(name = "Datasets", complex)]
pub struct DataCollection {

Check failure on line 24 in graph-data-processing/src/graphql/entities.rs

View workflow job for this annotation

GitHub Actions / lint

missing documentation for a struct
/// An opaque unique identifier for the data collection
pub data_collection_id: u32,
pub id: u32,
}
31 changes: 17 additions & 14 deletions graph-data-processing/src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
mod entities;

use async_graphql::{
Context, ComplexObject, EmptyMutation, EmptySubscription, Object, Schema, SchemaBuilder,
ComplexObject, Context, EmptyMutation, EmptySubscription, Object, Schema, SchemaBuilder,
};
use entities::{DataProcessing, DataCollection};
use sea_orm::{DatabaseConnection, EntityTrait, QueryFilter, ColumnTrait};
use entities::{DataCollection, DataProcessing};
use models::data_collection_file_attachment;
use sea_orm::{ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter};

/// The GraphQL schema exposed by the service
pub type RootSchema = Schema<Query, EmptyMutation, EmptySubscription>;
Expand All @@ -23,23 +23,26 @@ pub struct Query;
#[ComplexObject]
impl DataCollection {
/// Fetched all the processed data from data collection during a session
async fn processed_data(&self, ctx: &Context<'_>) -> Result<Vec<DataProcessing>, async_graphql::Error> {
let database = ctx.data::<DatabaseConnection>()?;
Ok(data_collection_file_attachment::Entity::find()
.filter(data_collection_file_attachment::Column::DataCollectionId.eq(self.data_collection_id))
.all(database)
.await?
.into_iter()
.map(DataProcessing::from)
.collect())
async fn processed_data(
&self,
ctx: &Context<'_>,
) -> Result<Vec<DataProcessing>, async_graphql::Error> {
let database = ctx.data::<DatabaseConnection>()?;
Ok(data_collection_file_attachment::Entity::find()
.filter(data_collection_file_attachment::Column::DataCollectionId.eq(self.id))
.all(database)
.await?
.into_iter()
.map(DataProcessing::from)
.collect())
}
}

#[Object]
impl Query {
/// Reference datasets resolver for the router
#[graphql(entity)]
async fn router_data_collection(&self, data_collection_id: u32) -> DataCollection {
DataCollection { data_collection_id }
async fn router_data_collection(&self, id: u32) -> DataCollection {
DataCollection { id }
}
}

0 comments on commit 23c4cfd

Please sign in to comment.