34 lines
898 B
Rust
34 lines
898 B
Rust
use crate::{models::modell::*, scalar::Id};
|
|
use async_graphql::{Context, FieldResult};
|
|
use sqlx::postgres::PgPool;
|
|
|
|
#[derive(Default)]
|
|
pub struct ModellMutation;
|
|
|
|
#[async_graphql::Object]
|
|
impl ModellMutation {
|
|
async fn create_modell(
|
|
&self,
|
|
ctx: &Context<'_>,
|
|
input: ModellCreateInput,
|
|
) -> FieldResult<Modell> {
|
|
let pool = ctx.data::<PgPool>()?;
|
|
let row = Modell::create(pool, &input).await?;
|
|
Ok(row)
|
|
}
|
|
|
|
async fn update_modell(
|
|
&self,
|
|
ctx: &Context<'_>,
|
|
input: ModellUpdateInput,
|
|
) -> FieldResult<Modell> {
|
|
let pool = ctx.data::<PgPool>()?;
|
|
let row = Modell::update(pool, &input).await?;
|
|
Ok(row)
|
|
}
|
|
async fn delete_modell(&self, ctx: &Context<'_>, id: Id) -> FieldResult<bool> {
|
|
let pool = ctx.data::<PgPool>()?;
|
|
Ok(Modell::delete(pool, &id).await?)
|
|
}
|
|
}
|