Files
axum-async-graphql/src/queries/hersteller.rs
2026-05-25 19:26:24 +02:00

23 lines
644 B
Rust

use async_graphql::{Context, FieldResult, Object};
use sqlx::postgres::PgPool;
use crate::models::hersteller::Hersteller;
#[derive(Default)]
pub struct HerstellerQuery {}
#[Object(extends)]
impl HerstellerQuery {
async fn hersteller(&self, ctx: &Context<'_>, id: uuid::Uuid) -> FieldResult<Hersteller> {
let pool = ctx.data::<PgPool>()?;
let row = Hersteller::read_one(pool, &id).await?;
Ok(row)
}
async fn alle_hersteller(&self, ctx: &Context<'_>) -> FieldResult<Vec<Hersteller>> {
let pool = ctx.data::<PgPool>()?;
let rows = Hersteller::read_all(pool).await?;
Ok(rows)
}
}