diff options
author | Santo Cariotti <santo@dcariotti.me> | 2024-08-21 11:59:50 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2024-08-21 12:04:28 +0200 |
commit | 185ba5270aaf94de9b91e4455be27db5198ec21e (patch) | |
tree | fc8d71e7ac6fd6b5b5aa8cc3fbf3c511d2b51342 /src/graphql | |
parent | c2b09dbb88591d9695c1cd2227c5d559b4a8e775 (diff) |
Reformat graphql mod
Diffstat (limited to 'src/graphql')
-rw-r--r-- | src/graphql/mod.rs | 2 | ||||
-rw-r--r-- | src/graphql/query.rs | 36 | ||||
-rw-r--r-- | src/graphql/routes.rs | 11 |
3 files changed, 49 insertions, 0 deletions
diff --git a/src/graphql/mod.rs b/src/graphql/mod.rs new file mode 100644 index 0000000..305f0d3 --- /dev/null +++ b/src/graphql/mod.rs @@ -0,0 +1,2 @@ +pub mod query; +pub mod routes; diff --git a/src/graphql/query.rs b/src/graphql/query.rs new file mode 100644 index 0000000..683885e --- /dev/null +++ b/src/graphql/query.rs @@ -0,0 +1,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, + } + } +} diff --git a/src/graphql/routes.rs b/src/graphql/routes.rs new file mode 100644 index 0000000..2380760 --- /dev/null +++ b/src/graphql/routes.rs @@ -0,0 +1,11 @@ +use crate::graphql::query::*; +use async_graphql::{EmptyMutation, EmptySubscription, Schema}; +use async_graphql_axum::{GraphQLRequest, GraphQLResponse}; +use std::sync::Arc; + +pub async fn graphql_handler( + schema: Arc<Schema<Query, EmptyMutation, EmptySubscription>>, + req: GraphQLRequest, +) -> GraphQLResponse { + schema.execute(req.into_inner()).await.into() +} |