oxidite_graphql/
schema.rs1use juniper::{RootNode, GraphQLObject, GraphQLInputObject, FieldResult};
2use crate::context::Context;
3
4pub struct QueryRoot;
6
7#[juniper::graphql_object(Context = Context)]
8impl QueryRoot {
9 async fn api_version() -> &str {
10 "1.0"
11 }
12
13 async fn health_check() -> bool {
14 true
15 }
16}
17
18pub struct MutationRoot;
20
21#[juniper::graphql_object(Context = Context)]
22impl MutationRoot {
23 async fn add_todo(text: String) -> FieldResult<String> {
24 Ok(format!("Added todo: {}", text))
25 }
26}
27
28pub fn create_schema() -> RootNode<'static, QueryRoot, MutationRoot, juniper::EmptySubscription<Context>> {
30 RootNode::new(
31 QueryRoot,
32 MutationRoot,
33 juniper::EmptySubscription::new(),
34 )
35}
36
37pub type GraphQLSchema = RootNode<'static, QueryRoot, MutationRoot, juniper::EmptySubscription<Context>>;
39
40#[derive(GraphQLObject)]
42pub struct Todo {
43 pub id: i32,
44 pub text: String,
45 pub completed: bool,
46}
47
48#[derive(GraphQLInputObject)]
50pub struct NewTodo {
51 pub text: String,
52 pub completed: Option<bool>,
53}