summaryrefslogtreecommitdiff
path: root/src/graphql/query.rs
blob: 683885e180cf7bff29b3eafacf363d42e713c5e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use async_graphql::{Context, Object};

pub struct Query;

#[Object]
impl Query {
    async fn api_version(&self) -> &'static str {
        "1.0"
    }

    /// Returns the sum of a and b
    async fn add<'ctx>(
        &self,
        _ctx: &Context<'ctx>,
        #[graphql(desc = "First value")] a: i32,
        #[graphql(desc = "Second value")] b: Option<i32>,
    ) -> i32 {
        // let state = ctx.data::<AppState>().unwrap();
        // let client = &*state.client;
        //
        // // Perform a database query
        // let rows = client
        //     .query("SELECT owner FROM payment", &[])
        //     .await
        //     .unwrap();
        // for row in rows {
        //     let owner: String = row.get(0);
        //     println!("{owner}");
        // }

        match b {
            Some(x) => a + x,
            None => a,
        }
    }
}