21 releases

Uses new Rust 2024

new 0.10.1 Apr 15, 2025
0.9.0 May 31, 2024
0.8.1 Nov 6, 2023
0.7.3 Mar 28, 2023

#479 in Network programming

Download history 18/week @ 2024-12-24 69/week @ 2024-12-31 140/week @ 2025-01-07 82/week @ 2025-01-14 49/week @ 2025-01-21 64/week @ 2025-01-28 50/week @ 2025-02-04 108/week @ 2025-02-11 110/week @ 2025-02-18 82/week @ 2025-02-25 29/week @ 2025-03-04 31/week @ 2025-03-11 141/week @ 2025-03-18 225/week @ 2025-03-25 115/week @ 2025-04-01 186/week @ 2025-04-08

669 downloads per month
Used in 2 crates

MIT license

67KB
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

~15–26MB
~498K SLoC