19 releases

0.9.0 May 31, 2024
0.8.1 Nov 6, 2023
0.8.0 Oct 17, 2023
0.7.3 Mar 28, 2023

#499 in Network programming

Download history 213/week @ 2024-07-23 47/week @ 2024-07-30 213/week @ 2024-08-06 56/week @ 2024-08-13 123/week @ 2024-08-20 107/week @ 2024-08-27 156/week @ 2024-09-03 35/week @ 2024-09-10 125/week @ 2024-09-17 188/week @ 2024-09-24 30/week @ 2024-10-01 26/week @ 2024-10-08 130/week @ 2024-10-15 68/week @ 2024-10-22 73/week @ 2024-10-29 117/week @ 2024-11-05

401 downloads per month
Used in 2 crates

MIT license

66KB
2K SLoC

Dynamic graphql

Build Status Latest Version Rust Documentation GitHub license

extendable and dynamic graphql schema definition for async-graphql

Usage

use dynamic_graphql::App;

mod foo {
    use dynamic_graphql::{App, ExpandObject, ExpandObjectFields, SimpleObject};

    use super::root::Query;

    #[derive(SimpleObject)]
    pub struct Foo {
        id: String,
        name: String,
    }

    #[derive(ExpandObject)]
    pub struct FooQuery<'a>(&'a Query);

    #[ExpandObjectFields]
    impl FooQuery<'_> {
        async fn foo(id: String) -> Foo {
            Foo {
                id,
                name: "test".to_string(),
            }
        }
    }

    #[derive(App)]
    pub struct FooApp(FooQuery<'static>);
}

mod root {
    use dynamic_graphql::SimpleObject;

    #[derive(SimpleObject)]
    #[graphql(root)]
    pub struct Query;
}

#[derive(App)]
struct App(root::Query, foo::FooApp);

#[tokio::test]
async fn test() {
    let schema = App::create_schema().finish().unwrap();

    let sdl = schema.sdl();

    assert_eq!(
        &sdl,
        r#"

type Foo {
	id: String!
	name: String!
}



type Query {
	foo(id: String!): Foo!
}


schema {
	query: Query
}
"#
    );

    let query = r#"
        query {
            foo(id: "1") {
                id
                name
            }
        }
    "#;

    let res = schema.execute(query).await;
    let data = res.data.into_json().unwrap();

    assert_eq!(
        data,
        serde_json::json!({ "foo": { "id": "1", "name": "test" } })
    );
}

Dependencies

~14–25MB
~471K SLoC