Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Federated compound soaking service #375

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions .devcontainer/Dockerfile.backend
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ RUN apt-get update \
sqlite3 pre-commit \
libopencv-dev clang libclang-dev \
&& rm -rf /var/lib/apt/lists/*

# Install Rover CLI for composing and precompiles rust router (gateway) for subgraphs
RUN curl -sSL https://rover.apollo.dev/nix/latest | sh\
&& curl -sSL https://router.apollo.dev/download/nix/latest | sh
1 change: 1 addition & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- chimp_chomp
- chimp_controller
- compound_library
- compound_soaking
- crystal_library
- pin_packing
- soakdb_sync
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@

# Developer Tooling
.vscode

# Apollo router
router
backend/router
# Generated supergraph schema
backend/supergraph.graphql
iamvigneshwars marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 21 additions & 0 deletions backend/Cargo.lock

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

1 change: 1 addition & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"chimp_protocol",
"crystal_library",
"compound_library",
"compound_soaking",
"graphql_endpoints",
"graphql_event_broker",
"opa_client",
Expand Down
10 changes: 10 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ COPY chimp_chomp/Cargo.toml chimp_chomp/Cargo.toml
COPY chimp_controller/Cargo.toml chimp_controller/Cargo.toml
COPY chimp_protocol/Cargo.toml chimp_protocol/Cargo.toml
COPY compound_library/Cargo.toml compound_library/Cargo.toml
COPY compound_soaking/Cargo.toml compound_soaking/Cargo.toml
COPY crystal_library/Cargo.toml crystal_library/Cargo.toml
COPY graphql_endpoints/Cargo.toml graphql_endpoints/Cargo.toml
COPY graphql_event_broker/Cargo.toml graphql_event_broker/Cargo.toml
Expand All @@ -29,6 +30,8 @@ RUN mkdir chimp_chomp/src \
&& echo "fn main() {}" > chimp_controller/src/main.rs \
&& mkdir compound_library/src \
&& echo "fn main() {}" > compound_library/src/main.rs \
&& mkdir compound_soaking/src \
&& echo "fn main() {}" > compound_soaking/src/main.rs \
&& mkdir crystal_library/src \
&& echo "fn main() {}" > crystal_library/src/main.rs \
&& mkdir graphql_endpoints/src \
Expand Down Expand Up @@ -56,6 +59,7 @@ RUN touch chimp_chomp/src/main.rs \
&& touch chimp_protocol/src/lib.rs \
&& touch chimp_controller/src/main.rs \
&& touch compound_library/src/main.rs \
&& touch compound_soaking/src/main.rs \
&& touch crystal_library/src/main.rs \
&& touch graphql_endpoints/src/lib.rs \
&& touch graphql_event_broker/src/lib.rs \
Expand Down Expand Up @@ -101,6 +105,12 @@ COPY --from=build /app/target/release/compound_library /compound_library

ENTRYPOINT ["/compound_library"]

FROM gcr.io/distroless/cc as compound_soaking

COPY --from=build /app/target/release/compound_soaking /compound_soaking

ENTRYPOINT ["/compound_soaking"]

FROM gcr.io/distroless/cc as crystal_library

COPY --from=build /app/target/release/crystal_library /crystal_library
Expand Down
4 changes: 0 additions & 4 deletions backend/compound_library/src/entities/mod.rs

This file was deleted.

21 changes: 19 additions & 2 deletions backend/compound_library/src/graphql/compound_instances_res.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::entities::{compound_instances, compound_types};
use crate::tables::{compound_instances, compound_types};
use async_graphql::{ComplexObject, Context, Object};
use chrono::Utc;
use opa_client::subject_authorization;
Expand Down Expand Up @@ -57,6 +57,23 @@ impl CompoundInstanceQuery {
.one(db)
.await?)
}

/// Reference resolver for compound instance in compound library subgraph
#[graphql(entity)]
async fn get_compound_instance_by_id(
&self,
ctx: &Context<'_>,
plate_id: Uuid,
well_number: i16,
) -> async_graphql::Result<Option<compound_instances::Model>> {
subject_authorization!("xchemlab.compound_library.read_compound", ctx).await?;
let db = ctx.data::<DatabaseConnection>()?;
Ok(compound_instances::Entity::find()
.filter(compound_instances::Column::PlateId.eq(plate_id))
.filter(compound_instances::Column::WellNumber.eq(well_number))
.one(db)
.await?)
}
}

#[Object]
Expand All @@ -66,7 +83,7 @@ impl CompoundInstanceMutation {
&self,
ctx: &Context<'_>,
plate_id: Uuid,
well_number: i16,
#[graphql(validator(minimum = 1, maximum = 288))] well_number: i16,
compound_type: String,
) -> async_graphql::Result<compound_instances::Model> {
let operator_id =
Expand Down
2 changes: 1 addition & 1 deletion backend/compound_library/src/graphql/compound_types_res.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::entities::{compound_instances, compound_types};
use crate::tables::{compound_instances, compound_types};
use async_graphql::{ComplexObject, Context, CustomValidator, InputValueError, Object};
use chrono::Utc;
use opa_client::subject_authorization;
Expand Down
2 changes: 1 addition & 1 deletion backend/compound_library/src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ pub type RootSchema = Schema<Query, Mutation, EmptySubscription>;
/// This function initializes the schema with default instances of `Query`,
/// `Mutation`, and `EmptySubscription`.
pub fn root_schema_builder() -> SchemaBuilder<Query, Mutation, EmptySubscription> {
Schema::build(Query::default(), Mutation::default(), EmptySubscription)
Schema::build(Query::default(), Mutation::default(), EmptySubscription).enable_federation()
}
6 changes: 3 additions & 3 deletions backend/compound_library/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#![warn(clippy::missing_docs_in_private_items)]
#![doc=include_str!("../README.md")]

/// This module defines the structure and schema of the database tables
/// through various entity structs.
mod entities;
/// This module sets up the GraphQL schema, including queries, mutations,
/// and subscriptions. It defines how data is queried and mutated through the API.
mod graphql;
/// This module is responsible for defining and applying database migrations.
mod migrator;
/// This module defines the structure and schema of the database tables
/// through various entity structs.
mod tables;

use async_graphql::extensions::Tracing;
use axum::{routing::get, Router, Server};
Expand Down
2 changes: 1 addition & 1 deletion backend/compound_library/src/migrator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::entities::{compound_instances, compound_types};
use crate::tables::{compound_instances, compound_types};
use axum::async_trait;
use sea_orm::{DbErr, DeriveMigrationName, Schema};
use sea_orm_migration::{MigrationTrait, MigratorTrait, SchemaManager};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use uuid::Uuid;
/// Represents a compound instance within the database.
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, SimpleObject)]
#[sea_orm(table_name = "compound_instances")]
#[graphql(name = "compund_instances", complex)]
#[graphql(name = "compound_instances", complex, shareable)]
pub struct Model {
/// ID of the plate on which the compound instance is located.
#[sea_orm(primary_key, auto_increment = false)]
Expand Down
4 changes: 4 additions & 0 deletions backend/compound_library/src/tables/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// The table storing compound instances information
pub mod compound_instances;
/// The table storing the compound types information
pub mod compound_types;
23 changes: 23 additions & 0 deletions backend/compound_soaking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "compound_soaking"
version = "0.1.0"
edition = "2021"

[dependencies]
async-graphql = { workspace = true }
axum = { workspace = true }
clap = { workspace = true }
chrono ={ workspace = true }
dotenvy = { workspace = true }
graphql_endpoints = { path = "../graphql_endpoints" }
opa_client = { path = "../opa_client", features = ["graphql"] }
sea-orm = { workspace = true, features = ["sqlx-postgres"] }
sea-orm-migration = { workspace = true }
the_paginator = { version = "0.1.0", path = "../the_paginator", features = [
"async-graphql",
] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
tokio = { workspace = true }
url = { workspace = true }
uuid = { workspace = true }
3 changes: 3 additions & 0 deletions backend/compound_soaking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Compound Soaking Service

This service keeps track of all the soaked compounds by various projects at the Diamond Light Source.
24 changes: 24 additions & 0 deletions backend/compound_soaking/src/graphql/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// A collection of resolvers relating to soaked compounds
mod soak_compound_res;
/// A collection of subgraphs extended from other services
mod subgraph_extensions;

use async_graphql::{EmptySubscription, MergedObject, Schema, SchemaBuilder};
use soak_compound_res::{SoakCompoundMutation, SoakCompoundQuery};

/// Combines all query resolvers into a single GraphQL `Query` type.
#[derive(Debug, Clone, MergedObject, Default)]
pub struct Query(SoakCompoundQuery);

/// Combines all mutations resolvers into a single GraphQL `Mutation` type.
#[derive(Debug, Clone, MergedObject, Default)]
pub struct Mutation(SoakCompoundMutation);

/// Type alias for the complete GraphQL schema.
pub type RootSchema = Schema<Query, Mutation, EmptySubscription>;

/// Initializes the schema with default instances of `Query`,
/// `Mutation`, and `EmptySubscription`.
pub fn root_schema_builder() -> SchemaBuilder<Query, Mutation, EmptySubscription> {
Schema::build(Query::default(), Mutation::default(), EmptySubscription).enable_federation()
}
Loading
Loading