Skip to content

Commit

Permalink
Federation with datasets service
Browse files Browse the repository at this point in the history
  • Loading branch information
iamvigneshwars committed Mar 21, 2024
1 parent bccb131 commit 53300de
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 24 deletions.
22 changes: 0 additions & 22 deletions graph-data-processing/src/graphql.rs

This file was deleted.

27 changes: 27 additions & 0 deletions graph-data-processing/src/graphql/entities.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use async_graphql::SimpleObject;
use models::data_collection_file_attachment;

#[derive(Clone, Debug, PartialEq, SimpleObject)]
#[graphql(name = "DataProcessing")]
pub struct DataProcessing {
/// 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,
}

impl From<data_collection_file_attachment::Model> for DataProcessing {
fn from(values: data_collection_file_attachment::Model) -> Self {
Self {
data_collection_file_attachment_id: values.data_collection_file_attachment_id,
file_full_path: values.file_full_path,
}
}
}

#[derive(SimpleObject)]
#[graphql(name = "Datasets", complex)]
pub struct DataCollection {
/// An opaque unique identifier for the data collection
pub data_collection_id: u32,
}
45 changes: 45 additions & 0 deletions graph-data-processing/src/graphql/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/// Collection of graphql entities
mod entities;

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

/// The GraphQL schema exposed by the service
pub type RootSchema = Schema<Query, EmptyMutation, EmptySubscription>;

/// A schema builder for the service
pub fn root_schema_builder() -> SchemaBuilder<Query, EmptyMutation, EmptySubscription> {
Schema::build(Query, EmptyMutation, EmptySubscription).enable_federation()
}

/// The root query of the service
#[derive(Debug, Clone, Default)]
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())
}
}

#[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 }
}
}
2 changes: 0 additions & 2 deletions models/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const TABLES_SPECS: &[&Table] = &[&Table {
"dataCollectionFileAttachmentId",
"dataCollectionId",
"fileFullPath",
"fileType",
"createTime"
],
}];

Expand Down

0 comments on commit 53300de

Please sign in to comment.